#include <bits/stdc++.h>
using namespace std;
int num[15];
int tag[15];
int a[15];
int b[15];
int digit[10];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[i] >> a[i] >> b[i];
  }
  int t;
  int cnt = 0;
  int k;
  int h = 0;
  int x, y;
  int tempx, tempy;
  int Printnum;
  int tt;
  int tx;
  int Cnt = 0;
  for (int i = 123; i <= 9999; i++) {
    x = y = 0;
    cnt = 0;
    t = i;
    k = 0;
    h = 3;
    memset(digit, 0, sizeof(digit));
    digit[0] = 4;
    do {
      digit[t % 10]++;
      digit[0]--;
      tag[h--] = t % 10;
      t /= 10;
    } while (t != 0);
    for (int j = 0; j < 10; j++) {
      if (digit[j] == 1) {
        k++;
      } else if (digit[j] > 1) {
        break;
      }
    }
    if (k == 4) {
      for (int j = 0; j < n; j++) {
        tempx = 0;
        tempy = 0;
        tt = num[j];
        tx = 1000;
        for (int p = 0; p < 4; p++) {
          if (tt / tx == tag[p]) {
            tempx++;
          } else if (digit[tt / tx] == 1) {
            tempy++;
          }
          tt %= tx;
          tx /= 10;
        }
        if (tempx == a[j] && tempy == b[j]) {
          cnt++;
        }
      }
      if (cnt == n) {
        Cnt++;
        if (Cnt > 1) {
          cout << "Need more data" << endl;
          return 0;
        } else {
          Printnum = i;
        }
      }
    }
  }
  if (Cnt == 1) {
    printf("%04d", Printnum);
  } else {
    cout << "Incorrect data" << endl;
  }
  return 0;
}
