#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, j, k, l;
  cin >> n;
  long long arr[n + 1], bull[n + 1], cow[n + 1];
  vector<long long> res;
  for (i = 1; i <= n; i++) cin >> arr[i] >> bull[i] >> cow[i];
  for (i = 0; i < 10000; i++) {
    long long f = 0, flag = 1;
    for (j = 1; j <= n && flag; j++) {
      long long n1 = i, n2 = arr[j], c = 0, b1 = 0, b2 = 0;
      vector<long long> v1, v2;
      while (c < 4) {
        v1.push_back(n1 % 10);
        n1 /= 10;
        c++;
      }
      c = 0;
      while (c < 4) {
        v2.push_back(n2 % 10);
        n2 /= 10;
        c++;
      }
      long long vis[4] = {0}, vis2[4] = {0};
      reverse(v1.begin(), v1.end());
      reverse(v2.begin(), v2.end());
      for (k = 0; k < 4; k++) {
        for (l = k + 1; l < 4; l++) {
          if (v1[k] == v1[l]) {
            flag = 0;
            break;
          }
        }
      }
      long long b = 0;
      c = 0;
      for (k = 0; k < 4; k++) {
        if (v1[k] == v2[k]) {
          b++;
          vis[k] = vis2[k] = 1;
        }
      }
      for (k = 0; k < 4; k++) {
        if (!vis[k]) {
          for (l = 0; l < 4; l++) {
            if (!vis2[l] && v2[l] == v1[k]) {
              c++;
              vis2[l] = vis[k] = 1;
            }
          }
        }
      }
      if (b == bull[j] && c == cow[j]) f++;
    }
    if (f == n && flag) res.push_back(i);
  }
  if (res.size() == 0)
    cout << "Incorrect data\n";
  else if (res.size() > 1)
    cout << "Need more data\n";
  else {
    vector<long long> v1;
    long long c = 0, n1 = res[0];
    while (c < 4) {
      v1.push_back(n1 % 10);
      n1 /= 10;
      c++;
    }
    reverse(v1.begin(), v1.end());
    for (i = 0; i < 4; i++) cout << v1[i];
    cout << '\n';
  }
  return 0;
}
