#include <bits/stdc++.h>
using namespace std;
int guess[10];
int a[10];
int b[10];
int main(void) {
  vector<int> pos;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> guess[i] >> a[i] >> b[i];
  for (int sk1 = 0; sk1 <= 9; sk1++) {
    for (int sk2 = 0; sk2 <= 9; sk2++) {
      for (int sk3 = 0; sk3 <= 9; sk3++) {
        for (int sk4 = 0; sk4 <= 9; sk4++) {
          set<int> ss;
          ss.insert(sk1);
          ss.insert(sk2);
          ss.insert(sk3);
          ss.insert(sk4);
          if (ss.size() < 4) continue;
          int ca = 0, cb = 0;
          bool good = true;
          for (int i = 0; i < n; i++) {
            int g4 = guess[i] % 10;
            int g3 = (guess[i] / 10) % 10;
            int g2 = (guess[i] / 100) % 10;
            int g1 = guess[i] / 1000;
            ca = (g4 == sk4) + (g3 == sk3) + (g2 == sk2) + (g1 == sk1);
            set<int> skm;
            skm.insert(g1);
            skm.insert(g2);
            skm.insert(g3);
            skm.insert(g4);
            skm.insert(sk1);
            skm.insert(sk2);
            skm.insert(sk3);
            skm.insert(sk4);
            cb = 8 - skm.size() - ca;
            if (ca != a[i] || cb != b[i]) {
              good = false;
              break;
            }
          }
          if (good) pos.push_back(sk1 * 1000 + sk2 * 100 + sk3 * 10 + sk4);
        }
      }
    }
  }
  if (pos.size() == 0)
    cout << "Incorrect data" << endl;
  else if (pos.size() > 1)
    cout << "Need more data" << endl;
  else {
    if (pos[0] < 1000) cout << 0;
    cout << pos[0];
  }
}
