#include <bits/stdc++.h>
using namespace std;
struct dat {
  int f, s;
  string str;
} a[100];
int ans[4];
int vis[11];
bool ok(int x) {
  int num = x;
  memset(ans, 0, sizeof ans);
  memset(vis, 0, sizeof vis);
  bool d = true;
  int k = 0;
  while (x) {
    if (vis[x % 10]) {
      d = false;
      break;
    }
    vis[x % 10] = 1;
    ans[k] = x % 10;
    k++;
    x = x / 10;
  }
  if (num < 1000) {
    if (vis[0]) return false;
  }
  reverse(ans, ans + 4);
  return d;
}
int main() {
  int i, k, j, l, n, m, cnt, pp, fin = 0, cn, last;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i].str >> a[i].f >> a[i].s;
  }
  pp = 0;
  for (int num = 100; num <= 9999; num++) {
    if (ok(num)) {
      pp = 0;
      for (i = 0; i < n; i++) {
        cnt = cn = 0;
        for (j = 0; j < 4; j++) {
          if ((a[i].str[j] - '0') == ans[j]) cnt++;
        }
        for (j = 0; j < 4; j++) {
          for (k = 0; k < 4; k++) {
            if ((a[i].str[j] - '0') == ans[k] && j != k) cn++;
          }
        }
        if (cnt == a[i].f && cn == a[i].s) pp++;
      }
      if (pp == n) {
        fin++;
        last = num;
      }
    }
  }
  if (fin == 1) {
    if (last < 1000) cout << 0;
    cout << last << endl;
  } else if (fin > 1) {
    cout << "Need more data" << endl;
  } else
    cout << "Incorrect data" << endl;
}
