#include <bits/stdc++.h>
using namespace std;
struct node {
  string num;
  int b, c;
} g[14];
bool cmp(const string, node &);
int main() {
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) cin >> g[i].num >> g[i].b >> g[i].c;
  int a, b, c, d, e, a_cnt = 0;
  string txt, ans;
  int cnt = 0;
  for (a = 0; a <= 9; a++) {
    for (b = 0; b <= 9; b++) {
      if (b == a) continue;
      for (c = 0; c <= 9; c++) {
        if (c == b || c == a) continue;
        for (d = 0; d <= 9; d++) {
          if (d == c || d == b || d == a) continue;
          txt.clear();
          txt += a + '0', txt += b + '0', txt += c + '0', txt += d + '0';
          cnt = 0;
          for (e = 0; e < k; e++) {
            if (cmp(txt, g[e])) cnt ^= (1 << e);
          }
          if (cnt == ((1 << k) - 1)) {
            a_cnt++;
            ans = txt;
          } else if (cnt == 0)
            continue;
        }
      }
    }
  }
  if (a_cnt > 1) {
    cout << "Need more data" << endl;
    return 0;
  } else if (a_cnt == 1) {
    cout << ans << endl;
    return 0;
  } else {
    cout << "Incorrect data" << endl;
    return 0;
  }
}
bool cmp(const string a, node &g) {
  int b = 0, c = 0, temp[10] = {0};
  string str = g.num;
  for (int i = 0; i < 4; i++) {
    if (a[i] == str[i]) b++;
    temp[a[i] - '0']++;
    temp[str[i] - '0']++;
  }
  for (int i = 0; i < 10; i++) {
    if (temp[i] == 2) c++;
  }
  c -= b;
  int cc = g.c, bb = g.b;
  if (cc == c && bb == b) return true;
  return false;
}
