#include <bits/stdc++.h>
using namespace std;
int n, a, b, na, ta, tb;
string k, s, r, ans;
bool can[(int)1e5];
bool chk(int k) {
  stringstream ss;
  ss << k;
  r = ss.str();
  if (k < 1000) r = "0" + r;
  for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 4; j++) {
      if (r[i] == r[j]) return 0;
    }
  }
  return 1;
}
void see(string k) {
  for (int i = 100; i < 9999; i++) {
    ta = tb = 0;
    stringstream ss;
    ss << i;
    s = ss.str();
    if (i < 1000) s = "0" + s;
    for (int j = 0; j < 4; j++) {
      for (int l = 0; l < 4; l++) {
        if (s[j] == k[l] && j == l)
          ta++;
        else if (s[j] == k[l])
          tb++;
      }
    }
    if (ta != a || tb != b) can[i] = 0;
  }
}
int main() {
  scanf("%d", &n);
  memset(can, 1, sizeof(can));
  while (n--) {
    na = 0;
    cin >> k >> a >> b;
    see(k);
  }
  for (int i = 100; i < 9999; i++)
    if (can[i] && chk(i)) {
      stringstream ss;
      ss << i;
      ans = ss.str();
      if (i < 1000) ans = "0" + ans;
      na++;
    }
  if (na > 1)
    printf("Need more data");
  else if (na == 0)
    printf("Incorrect data");
  else
    cout << ans;
  return 0;
}
