/*
Author: 2486
Memory: 1604 KB		Time: 46 MS
Language: C++		Result: Accepted
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=100+5;
int n;
struct state {
    int num,c,d;
} sts[maxn];
int B(int x,int y) {//判断包含几个符合条件的数
    int a[4],b[4];
    int al=0,bl=0;
    while(x) {
        a[al++]=x%10;
        x/=10;
    }
    while(y) {
        b[bl++]=y%10;
        y/=10;
    }
    int ans=0;
    int vis[15]= {0};
    for(int i=0; i<4; i++) {
        vis[b[i]]++;
    }
    for(int i=0; i<4; i++) {
        if(vis[a[i]])
            vis[a[i]]--;
    }
    for(int i=0; i<10; i++) {
        ans+=vis[i];
    }
    return 4-ans;
}
int D(int x,int y) {//判断含有一个位置正确的数
    int a[4],b[4];
    int al=0,bl=0;
    while(x) {
        a[al++]=x%10;
        x/=10;
    }
    while(y) {
        b[bl++]=y%10;
        y/=10;
    }
    int ans=0;
    for(int i=0; i<4; i++) {
        if(b[i]==a[i])ans++;
    }
    return ans;
}
bool C(int m) {
    for(int i=0; i<n; i++) {
        if(!(B(sts[i].num,m)==sts[i].c&&D(sts[i].num,m)==sts[i].d)) {
            return false;
        }
    }
    return true;
}
int main() {
    while(~scanf("%d",&n),n) {
        for(int i=0; i<n; i++) {
            scanf("%d%d%d",&sts[i].num,&sts[i].c,&sts[i].d);
        }
        int ds=0;
        int flag=0;
        for(int i=1000; i<10000; i++) {
            if(C(i)) {
                ds=i;
                flag++;
            }
        }
        if(flag!=1)printf("Not sure\n");
        else printf("%d\n",ds);
    }
    return 0;
}