#include <bits/stdc++.h>
int a1[15], s[15], b1[15], c1[1000];
int main() {
  int i, j, n, m;
  int a, b, c, d;
  int aa, bb, cc, dd;
  while (scanf("%d", &n) != EOF) {
    for (i = 0; i < n; i++) scanf("%d%d%d", &s[i], &a1[i], &b1[i]);
    int cnt = 0;
    for (i = 0; i < 10000; i++) {
      a = i / 1000;
      b = i / 100 % 10;
      c = i / 10 % 10;
      d = i % 10;
      if (a == b || b == c || c == d || a == c || a == d || b == d) continue;
      int flag = 0;
      for (j = 0; j < n; j++) {
        int ss = 0, sk = 0;
        aa = s[j] / 1000;
        bb = s[j] / 100 % 10;
        cc = s[j] / 10 % 10;
        dd = s[j] % 10;
        if (aa == a) ss++;
        if (bb == b) ss++;
        if (cc == c) ss++;
        if (dd == d) ss++;
        if (a == bb || a == cc || a == dd) sk++;
        if (b == aa || b == cc || b == dd) sk++;
        if (c == aa || c == bb || c == dd) sk++;
        if (d == aa || d == bb || d == cc) sk++;
        if (ss == a1[j] && sk == b1[j]) flag++;
      }
      if (flag == n) c1[cnt++] = i;
    }
    if (cnt == 0)
      puts("Incorrect data");
    else if (cnt == 1)
      printf("%04d\n", c1[0]);
    else if (cnt > 1)
      puts("Need more data");
  }
  return 0;
}
