#include <bits/stdc++.h>
using namespace std;
vector<string> v;
string VRATI;
bool bio[10050];
void GEN() {
  string t;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      for (int z = 0; z < 10; z++)
        for (int g = 0; g < 10; g++) {
          if (i == j || i == z || i == g) continue;
          if (j == z || j == g) continue;
          if (z == g) continue;
          t = "....";
          t[0] = i + '0';
          t[1] = j + '0';
          t[2] = z + '0';
          t[3] = g + '0';
          v.push_back(t);
        }
}
int x[15];
void SOLVE() {
  string s;
  int a, b, A, B;
  cin >> s >> a >> b;
  for (int i = 0; i < v.size(); i++)
    if (!bio[i]) {
      memset(x, 0, sizeof x);
      A = 0;
      B = 0;
      for (int j = 0; j < 4; j++) {
        x[s[j] - '0']++;
        x[v[i][j] - '0']++;
        if (s[j] == v[i][j]) A++;
      }
      for (int j = 0; j < 10; j++)
        if (x[j] == 2) B++;
      B -= A;
      if (a != A || b != B) bio[i] = true;
    }
}
int CHECK() {
  int tmp = 0;
  for (int i = 0; i < v.size(); i++)
    if (!bio[i]) {
      VRATI = v[i];
      tmp++;
    }
  return tmp;
}
int main() {
  GEN();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) SOLVE();
  int ret = CHECK();
  if (ret > 1) {
    cout << "Need more data" << endl;
    return 0;
  }
  if (ret == 0) {
    cout << "Incorrect data" << endl;
    return 0;
  }
  cout << VRATI << endl;
  return 0;
}
