#include <bits/stdc++.h>
using namespace std;
vector<string> va(10);
vector<int> vb(10), vc(10);
int n;
bool valid(string x) {
  string ops(4, '?');
  for (int i = (0), _i = (n); i < _i; ++i) {
    int b = 0, c = 0;
    for (int j = (0), _j = (4); j < _j; ++j)
      if (x[j] == va[i][j]) b++;
    if (b != vb[i]) return false;
    for (int j = (0), _j = (4); j < _j; ++j) {
      for (int k = (0), _k = (4); k < _k; ++k) {
        if (j == k) continue;
        if (va[i][j] == x[k]) c++;
      }
    }
    if (c != vc[i]) return false;
  }
  return true;
}
int main() {
  int cnt = 0;
  scanf("%d", &n);
  for (int i = (0), _i = (n); i < _i; ++i) cin >> va[i] >> vb[i] >> vc[i];
  string sol;
  for (char i1 = '0'; i1 <= '9'; i1++) {
    for (char i2 = '0'; i2 <= '9'; i2++) {
      if (i1 == i2) continue;
      for (char i3 = '0'; i3 <= '9'; i3++) {
        if (i1 == i3 || i2 == i3) continue;
        for (char i4 = '0'; i4 <= '9'; i4++) {
          if (i1 == i4 || i2 == i4 || i3 == i4) continue;
          string act;
          act.push_back(i1);
          act.push_back(i2);
          act.push_back(i3);
          act.push_back(i4);
          if (valid(act)) {
            cnt++;
            sol = act;
          }
        }
      }
    }
  }
  if (cnt) {
    if (cnt > 1)
      printf("Need more data\n");
    else
      cout << sol << endl;
  } else
    printf("Incorrect data\n");
}
