#include <bits/stdc++.h>
using namespace std;
int n;
string d[11];
int b[11], k[11];
int main() {
  cin >> n;
  for (int(i) = 0; (i) < (n); ++(i)) cin >> d[i] >> b[i] >> k[i];
  int ans = -1;
  for (int(i) = 0; (i) < (10000); ++(i)) {
    string s = "";
    s += '0' + (i / 1000);
    s += '0' + (i % 1000) / 100;
    s += '0' + (i % 100) / 10;
    s += '0' + i % 10;
    string t = s;
    sort((t).begin(), (t).end());
    bool ok = 1;
    for (int(l) = 0; (l) < (3); ++(l))
      if (t[l] == t[l + 1]) ok = 0;
    for (int(j) = 0; (j) < (n); ++(j)) {
      int c1[11];
      int c2[11];
      memset((c1), 0, sizeof((c1)));
      memset((c2), 0, sizeof((c2)));
      for (int(l) = 0; (l) < (4); ++(l)) {
        c1[s[l] - '0']++;
        c2[d[j][l] - '0']++;
      }
      int a1 = 0, a2 = 0;
      for (int(l) = 0; (l) < (10); ++(l)) a2 += min(c1[l], c2[l]);
      for (int(l) = 0; (l) < (4); ++(l))
        if (s[l] == d[j][l]) {
          a1++;
          a2--;
        }
      if (a1 != b[j] || a2 != k[j]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      if (ans == -1)
        ans = i;
      else {
        cout << "Need more data\n";
        return 0;
      }
    }
  }
  if (ans == -1)
    cout << "Incorrect data\n";
  else
    cout << ans / 1000 << (ans % 1000) / 100 << (ans % 100) / 10 << ans % 10
         << endl;
}
