#include <bits/stdc++.h>
struct Guess {
  char s[5];
  int b, c;
  int t[11];
} g[11];
int a[5];
int chan(int x) {
  int f[11];
  for (int i = 0; i < 4; i++) a[i] = 0;
  for (int i = 0; i < 10; i++) f[i] = 0;
  int k = 0;
  while (x || k < 4) {
    f[x % 10]++;
    if (f[x % 10] > 1) return 0;
    a[k++] = x % 10;
    x /= 10;
  }
  for (int i = 0; i < 2; i++) {
    int tem = a[i];
    a[i] = a[4 - i - 1];
    a[3 - i] = tem;
  }
  return 1;
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s%d%d", g[i].s, &g[i].b, &g[i].c);
    for (int j = 0; j <= 9; j++) g[i].t[j] = 0;
    for (int j = 0; j < 4; j++) g[i].t[g[i].s[j] - '0']++;
  }
  int flag = 0;
  int ans, res;
  for (ans = 9999; ans > 0; ans--) {
    if (!chan(ans)) {
      continue;
    }
    int i;
    for (i = 0; i < N; i++) {
      int bb = 0, cc = 0;
      for (int j = 0; j < 4; j++) {
        if (a[j] == g[i].s[j] - '0')
          bb++;
        else if (g[i].t[a[j]])
          cc++;
      }
      if (bb != g[i].b || cc != g[i].c) {
        break;
      }
    }
    if (i == N) {
      res = ans;
      flag++;
    }
  }
  if (flag == 0)
    printf("Incorrect data\n");
  else if (flag == 1)
    printf("%04d\n", res);
  else
    printf("Need more data\n");
  return 0;
}
