#include <bits/stdc++.h>
using namespace std;
int n, b, c, t, mb, mc, t1, t2, t3, a[10000], r, cn, d[4], d0[4];
int main() {
  cin >> n;
  for (int k = 0; k < 10000; k++) {
    int b = 1;
    t = k;
    for (int i = 0; i < 4; i++) {
      d[i] = t % 10;
      t /= 10;
    }
    for (int i = 0; i < 4; i++)
      for (int j = i + 1; j < 4; j++)
        if (d[i] == d[j]) b = 0;
    a[k] = b;
  }
  for (int i = 0; i < n; i++) {
    cin >> t1 >> b >> c;
    for (int j = 0; j < 4; j++) {
      d0[j] = t1 % 10;
      t1 /= 10;
    }
    for (int j = 0; j < 10000; j++) {
      if (a[j] == 0) continue;
      t = j;
      mb = 0;
      mc = 0;
      for (int k = 0; k < 4; k++) {
        d[k] = t % 10;
        t /= 10;
      }
      for (int k = 0; k < 4; k++)
        if (d[k] == d0[k]) mb++;
      for (int k = 0; k < 4; k++)
        for (int l = 0; l < 4; l++)
          if (d[k] == d0[l]) mc++;
      mc -= mb;
      if (mb != b || mc != c) a[j] = 0;
    }
  }
  for (int i = 0; i < 10000; i++)
    if (a[i] == 1) {
      cn++;
      r = i;
    }
  if (!cn)
    cout << "Incorrect data" << endl;
  else if (cn == 1) {
    if (r < 1000) cout << "0";
    cout << r << endl;
  } else
    cout << "Need more data" << endl;
}
