#include <bits/stdc++.h>
using namespace std;
struct rek {
  vector<int> a;
  int b, c;
};
bool Rozne(vector<int>& a) {
  for (int i = 0; i < 4; ++i)
    for (int j = 0; j < 4; ++j)
      if (i != j && a[i] == a[j]) return false;
  return true;
}
int LiczB(vector<int>& a, vector<int>& b) {
  int il = 0;
  for (int i = 0; i < 4; ++i)
    if (a[i] == b[i]) ++il;
  return il;
}
int LiczC(vector<int>& a, vector<int>& b) {
  int il = 0;
  for (int i = 0; i < 4; ++i)
    for (int j = 0; j < 4; ++j)
      if (i != j && a[i] == b[j]) ++il;
  return il;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  string a;
  int b, c;
  vector<rek> pyt(n);
  for (int i = 0; i < n; ++i) {
    cin >> a >> b >> c;
    for (int j = 0; j < 4; ++j) pyt[i].a.push_back(a[j] - '0');
    pyt[i].b = b;
    pyt[i].c = c;
  }
  vector<vector<int> > odp;
  for (int w = 0; w < 10; ++w) {
    for (int x = 0; x < 10; ++x) {
      for (int y = 0; y < 10; ++y) {
        for (int z = 0; z < 10; ++z) {
          vector<int> t(4);
          t[0] = w;
          t[1] = x;
          t[2] = y;
          t[3] = z;
          if (Rozne(t)) {
            bool db = true;
            for (int i = 0; i < n; ++i) {
              int bt = LiczB(pyt[i].a, t);
              int ct = LiczC(pyt[i].a, t);
              if (bt != pyt[i].b || ct != pyt[i].c) db = false;
            }
            if (db) odp.push_back(t);
          }
        }
      }
    }
  }
  if (odp.size() == 0)
    cout << "Incorrect data";
  else {
    if (odp.size() > 1)
      cout << "Need more data";
    else
      cout << odp[0][0] << odp[0][1] << odp[0][2] << odp[0][3];
  }
  return 0;
}
