#include <bits/stdc++.h>
using namespace std;
int ok[10];
int a[20][5];
int b[20][10];
int q[20];
int y[20];
int now[10];
int main() {
  int n;
  int ans = 0;
  memset(q, 0, sizeof(q));
  memset(y, 0, sizeof(y));
  memset(b, 0, sizeof(b));
  memset(a, 0, sizeof(a));
  cin >> n;
  int num = 0;
  for (int i = 1; i <= n; i++) {
    int e, r, t;
    char p;
    for (int j = 1; j <= 4; j++) {
      p = getchar();
      if (p == '\n') p = getchar();
      a[i][j] = p - '0';
      b[i][p - '0'] = 1;
    }
    cin >> r >> t;
    q[i] = r;
    y[i] = t;
  }
  for (int i = 1; i <= 9999; i++) {
    int z = i;
    memset(ok, 0, sizeof(ok));
    memset(now, 0, sizeof(now));
    int isok = 1;
    for (int j = 1; j <= 4; j++) {
      int g = z % 10;
      if (ok[g]) {
        isok = 0;
        break;
      } else {
        ok[g] = 1;
        now[j] = g;
      }
      z = z / 10;
    }
    if (!isok) continue;
    for (int j = 1; j <= n; j++) {
      int num1 = 0;
      int num2 = 0;
      for (int k = 1; k <= 4; k++) {
        if (a[j][k] == now[5 - k]) {
          num1++;
        }
      }
      for (int k = 0; k <= 9; k++) {
        if (ok[k] == 1 && b[j][k] == 1) num2++;
      }
      if (num1 != q[j] || (num2 - num1) != y[j]) {
        isok = 0;
      }
    }
    if (isok) {
      num++;
      ans = i;
    }
  }
  if (num == 1) {
    if (ans > 1000)
      cout << ans << endl;
    else
      cout << "0" << ans << endl;
  }
  if (num == 0) cout << "Incorrect data" << endl;
  if (num > 1) cout << "Need more data" << endl;
  return 0;
}
