#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
int main() {
  int n;
  cin >> n;
  int ar[10000];
  char s[5];
  int a, b;
  memset(ar, 0, sizeof(ar));
  for (int i = 0; i <= 9999; i++) {
    char str[5];
    sprintf(str, "%04d", i);
    if (str[0] == str[1] || str[0] == str[2] || str[0] == str[3] ||
        str[1] == str[2] || str[1] == str[3] || str[2] == str[3])
      continue;
    ar[i] = 1;
  }
  for (int i = 0; i < n; i++) {
    scanf("%s%d%d", s, &a, &b);
    for (int j = 0; j <= 9999; j++) {
      if (ar[j] == 1) {
        char st[5];
        sprintf(st, "%04d", j);
        int cb = 0, cw = 0;
        for (int k = 0; k < 4; k++) {
          if (st[k] == s[k]) ++cb;
        }
        if (st[0] == s[1] || st[0] == s[2] || st[0] == s[3]) ++cw;
        if (st[1] == s[0] || st[1] == s[2] || st[1] == s[3]) ++cw;
        if (st[2] == s[0] || st[2] == s[1] || st[2] == s[3]) ++cw;
        if (st[3] == s[0] || st[3] == s[1] || st[3] == s[2]) ++cw;
        if (cb != a || cw != b) {
          ar[j] = 0;
        }
      }
    }
  }
  int ans;
  int count = 0;
  for (int i = 0; i <= 9999; i++) {
    if (ar[i] == 0)
      continue;
    else if (ar[i] == 1) {
      ans = i;
      ++count;
    }
  }
  if (count == 1) {
    printf("%04d\n", ans);
  } else if (count == 0) {
    printf("Incorrect data\n");
  } else
    printf("Need more data\n");
  return 0;
}
