#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
  char s[10];
  int p, t;
} a[15];
int judge(char *A) {
  int t1, t2;
  int i, j, k, cnt;
  int f[4];
  cnt = 0;
  for (i = 0; i < n; i++) {
    t1 = 0, t2 = 0;
    for (j = 0; j < 4; j++) {
      if (a[i].s[j] == A[j]) t1++;
      f[j] = 0;
    }
    for (j = 0; j < 4; j++) {
      for (k = 0; k < 4; k++) {
        if (!f[k] && A[j] == a[i].s[k]) {
          f[k] = 1;
          t2++;
          break;
        }
      }
    }
    t2 -= t1;
    if (t1 == a[i].p && t2 == a[i].t) cnt++;
  }
  if (cnt == n) return 1;
  return 0;
}
int main() {
  char str[10];
  char now[2][10];
  int i, j, k, ii, kk, flag, cnt;
  while (scanf("%d", &n) != EOF) {
    flag = 0;
    for (i = 0; i < n; i++) {
      scanf("%s", a[i].s);
      scanf("%d %d", &a[i].p, &a[i].t);
    }
    cnt = 0;
    for (i = 0; i < 10; i++) {
      str[0] = '0' + i;
      for (j = i + 1; j < 10; j++) {
        str[1] = '0' + j;
        for (k = j + 1; k < 10; k++) {
          str[2] = '0' + k;
          for (ii = k + 1; ii < 10; ii++) {
            str[3] = '0' + ii;
            str[4] = 0;
            if (judge(str)) {
              strcpy(now[cnt], str);
              cnt++;
            }
            while (next_permutation(str, str + 4)) {
              if (judge(str)) {
                strcpy(now[cnt], str);
                cnt++;
              }
              if (cnt == 2) {
                break;
              }
            }
            if (cnt == 2) break;
          }
          if (cnt == 2) break;
        }
        if (cnt == 2) break;
      }
      if (cnt == 2) break;
    }
    if (cnt == 0)
      puts("Incorrect data");
    else if (cnt == 1)
      puts(now[0]);
    else
      puts("Need more data");
  }
  return 0;
}
