#include <bits/stdc++.h>
typedef struct {
  int a, b, c, d;
  int x, y;
} node;
node a[11];
int n;
bool check(int i, int j, int k, int l) {
  int x[4], y[4];
  int ii, t1 = 0, t2 = 0;
  for (ii = 1; ii <= n; ii++) {
    t1 = t2 = 0;
    if (a[ii].a == i)
      t1++;
    else if (a[ii].a == j || a[ii].a == k || a[ii].a == l)
      t2++;
    if (a[ii].b == j)
      t1++;
    else if (a[ii].b == i || a[ii].b == k || a[ii].b == l)
      t2++;
    if (a[ii].c == k)
      t1++;
    else if (a[ii].c == i || a[ii].c == j || a[ii].c == l)
      t2++;
    if (a[ii].d == l)
      t1++;
    else if (a[ii].d == i || a[ii].d == k || a[ii].d == j)
      t2++;
    if (t1 != a[ii].x || t2 != a[ii].y) return false;
  }
  return true;
}
int main() {
  int i, j, k, l, num;
  int ct = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %d %d", &num, &a[i].x, &a[i].y);
    a[i].a = num / 1000;
    num %= 1000;
    a[i].b = num / 100;
    num %= 100;
    a[i].c = num / 10;
    num %= 10;
    a[i].d = num;
  }
  num = 0;
  for (i = 0; i <= 9; i++)
    for (j = 0; j <= 9; j++) {
      if (j == i) continue;
      for (k = 0; k <= 9; k++) {
        if (k == i || k == j) continue;
        for (l = 0; l <= 9; l++) {
          if (l == i || l == j || l == k) continue;
          if (check(i, j, k, l) == true) {
            num = i * 1000 + j * 100 + k * 10 + l;
            ct++;
          }
        }
      }
    }
  if (ct == 0)
    printf("Incorrect data\n");
  else if (ct == 1)
    if (num > 1000)
      printf("%d\n", num);
    else
      printf("0%d\n", num);
  else
    printf("Need more data\n");
  return 0;
}
