#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
struct node {
  char num[5];
  int a[10];
  int b, c;
};
node arr[MAXN];
int ans;
char num[5];
int ansnum;
int d[10];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int t = 0;
  for (int i = 0; i < n; i++) {
    cin >> t >> arr[i].b >> arr[i].c;
    int index = 3;
    while (t) {
      arr[i].num[index] = t % 10 + '0';
      t /= 10;
      index--;
    }
    while (index >= 0) {
      arr[i].num[index] = '0';
      index--;
    }
    arr[i].a[arr[i].num[0] - '0'] = 1;
    arr[i].a[arr[i].num[1] - '0'] = 1;
    arr[i].a[arr[i].num[2] - '0'] = 1;
    arr[i].a[arr[i].num[3] - '0'] = 1;
  }
  for (int i = 0; i < 10000; i++) {
    memset(num, 0, sizeof num);
    memset(d, 0, sizeof d);
    int temp = i;
    int index = 3;
    bool flag = true;
    while (temp) {
      num[index] = temp % 10 + '0';
      if (d[num[index] - '0']) {
        flag = false;
      }
      d[num[index] - '0']++;
      temp /= 10;
      index--;
    }
    while (index >= 0) {
      num[index] = '0';
      if (d[num[index] - '0']) {
        flag = false;
      }
      d[num[index] - '0']++;
      index--;
    }
    if (flag == false) {
      continue;
    }
    int ans1 = 0;
    for (int j = 0; j < n; j++) {
      int cnta = 0, cntb = 0;
      for (int k = 0; k < 4; k++) {
        if (arr[j].num[k] == num[k]) {
          cnta++;
        } else if (arr[j].a[num[k] - '0']) {
          cntb++;
        }
      }
      if (cnta == arr[j].b && cntb == arr[j].c) {
        ans1++;
      }
    }
    if (ans1 == n) {
      ans++;
      ansnum = i;
    }
  }
  if (ans == 1) {
    cout << setw(4) << setfill('0') << ansnum << endl;
  } else if (ans > 1) {
    cout << "Need more data" << endl;
  } else {
    cout << "Incorrect data" << endl;
  }
  return 0;
}
