#include <bits/stdc++.h>
using namespace std;
int getbull(string s1, string s2) {
  int res = 0;
  for (int i = 0; i < 4; i++)
    if (s1[i] == s2[i]) res++;
  return res;
}
int getcow(string s1, string s2) {
  int res = 0;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
      if (s1[i] == s2[j] && i != j) res++;
  return res;
}
int main() {
  int n;
  cin >> n;
  string arr[10000] = {};
  int rrr[10000] = {};
  int dif = 0;
  for (int i = 0; i <= 9; i++)
    for (int j = 0; j <= 9; j++)
      for (int k = 0; k <= 9; k++)
        for (int f = 0; f <= 9; f++)
          if (i != j && i != k && i != f && j != k && j != f && k != f) {
            dif++;
            char ii = i + '0', jj = j + '0', kk = k + '0', ff = f + '0';
            arr[dif] += ii;
            arr[dif] += jj;
            arr[dif] += kk;
            arr[dif] += ff;
          }
  for (int i = 1; i <= 5040; i++) rrr[i] = 1;
  for (int i = 0; i < n; i++) {
    int b, c;
    string ns;
    cin >> ns >> b >> c;
    for (int j = 1; j <= 5040; j++) {
      int nb = getbull(arr[j], ns);
      int nc = getcow(arr[j], ns);
      if (nb != b || nc != c) rrr[j] = 0;
    }
  }
  int trues = 0;
  for (int i = 1; i <= 5040; i++)
    if (rrr[i]) trues++;
  if (trues > 1) cout << "Need more data";
  if (!trues) cout << "Incorrect data";
  if (trues == 1) {
    for (int i = 1; i <= 5040; i++)
      if (rrr[i]) cout << arr[i];
  }
}
