#include <bits/stdc++.h>
using namespace std;
char d[4];
void getd(int n) {
  int q1 = n / 1000;
  d[0] = q1 + '0';
  n -= q1 * 1000;
  int q2 = n / 100;
  d[1] = q2 + '0';
  n -= q2 * 100;
  int q3 = n / 10;
  d[2] = q3 + '0';
  n -= q3 * 10;
  d[3] = n + '0';
}
bool ok() {
  for (int i = 0; i < 4; i++)
    for (int j = i + 1; j < 4; j++)
      if (d[i] == d[j]) return 0;
  return 1;
}
int main() {
  char c[4];
  bool map[10005];
  int bull, cow, n;
  while (cin >> n) {
    memset(map, 1, sizeof(map));
    int f = 0;
    while (n--) {
      cin >> c >> bull >> cow;
      if (bull == 3 && cow == 1) {
        f = 1;
        continue;
      }
      for (int i = 0; i < 10000; i++) {
        if (!map[i]) continue;
        bool pp[5];
        memset(pp, 0, sizeof(pp));
        getd(i);
        if (!ok()) {
          map[i] = 0;
          continue;
        }
        int a1 = 0, a2 = 0;
        for (int i = 0; i < 4; i++) {
          if (c[i] == d[i])
            a1++, pp[i] = 1;
          else if (c[i] != d[i]) {
            for (int j = 0; j < 4; j++)
              if (d[i] == c[j]) {
                if (!pp[j])
                  pp[j] = 1, a2++;
                else
                  a2 += 99999999;
                break;
              }
          }
        }
        if (a1 == bull && a2 == cow) continue;
        map[i] = 0;
      }
    }
    int num = 0;
    for (int i = 0; i < 10000; i++)
      if (map[i]) num++;
    if (num == 0 || f)
      puts("Incorrect data");
    else if (num == 1) {
      for (int i = 0; i <= 9999; i++)
        if (map[i]) {
          getd(i);
          cout << d << endl;
          break;
        }
    } else
      puts("Need more data");
  }
  return 0;
}
