#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  bool ps[10005];
  for (int i = 1; i <= 9999; ++i) ps[i] = 1;
  vector<pair<int, pair<int, int>>> v;
  for (int i = 0; i < (n); i++) {
    int nm, b, c;
    cin >> nm >> b >> c;
    v.push_back({nm, {b, c}});
  }
  for (int i = 1; i <= 9999; ++i) {
    int a[4];
    int num = i;
    for (int j = 0; j < (4); j++) {
      a[3 - j] = num % 10;
      num /= 10;
    }
    for (int j = 0; j < (4); j++) {
      for (int k = 0; k < (4); k++) {
        if (j != k && a[j] == a[k]) ps[i] = 0;
      }
    }
    if (ps[i]) {
      for (int z = 0; z < (n); z++) {
        if (ps[i] == 0) break;
        int num2 = v[z].first, b, c, a2[4];
        b = v[z].second.first;
        c = v[z].second.second;
        bool fine = 1;
        for (int j = 0; j < (4); j++) {
          a2[3 - j] = num2 % 10;
          num2 /= 10;
        }
        for (int t = 0; t < 4; t++)
          if (a[t] == a2[t]) b--;
        for (int t = 0; t < 4; t++) {
          for (int p = 0; p < 4; p++) {
            if (p != t && a[p] == a2[t]) c--;
          }
        }
        if (b || c) fine = 0;
        if (!fine) ps[i] = 0;
      }
    }
  }
  int ans = 0, cs = -1;
  for (int i = 0; i < (9999); i++) {
    if (ps[i]) {
      ans++;
      cs = i;
    }
  }
  if (ans > 1)
    puts("Need more data");
  else if (ans == 0)
    puts("Incorrect data");
  else
    printf("%04d\n", cs);
  return 0;
}
