#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 5, inf = 0x3f3f3f3f, mod = 998244353;
const long long INF = 0x3f3f3f3f3f3f3f3f;
string s[maxn], str;
int bull, cow, cnt, n, vis[maxn];
bool flag[5];
void init() {
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      if (j == i) continue;
      for (int k = 0; k <= 9; k++) {
        if (k == j || k == i) continue;
        for (int q = 0; q <= 9; q++) {
          if (q == k || q == j || q == i) continue;
          s[++cnt] += i + '0';
          s[cnt] += j + '0';
          s[cnt] += k + '0';
          s[cnt] += q + '0';
        }
      }
    }
  }
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> str >> cow >> bull;
    int temp1 = bull, temp2 = cow;
    for (int j = 1; j <= cnt; j++) {
      bull = temp1, cow = temp2;
      if (vis[j] == -1) continue;
      memset(flag, 0, sizeof(flag));
      for (int k = 0; k < 4; k++) {
        if (s[j][k] == str[k]) {
          cow--;
          flag[k] = 1;
        }
      }
      for (int k = 0; k < 4; k++) {
        if (s[j][k] != str[k]) {
          for (int t = 0; t < 4; t++) {
            if (flag[t]) continue;
            if (str[k] == s[j][t]) {
              flag[t] = 1;
              bull--;
              break;
            }
          }
        }
      }
      if (cow == 0 && bull == 0) {
        vis[j] = 1;
      } else {
        vis[j] = -1;
      }
    }
  }
  string ans;
  int sum = 0;
  for (int i = 1; i <= cnt; i++) {
    if (vis[i] == 1) {
      ans = s[i];
      sum++;
    }
  }
  if (sum == 0) {
    printf("Incorrect data\n");
  } else if (sum == 1) {
    cout << ans << '\n';
  } else if (sum >= 2) {
    printf("Need more data\n");
  }
  return 0;
}
