#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
vector<int> get(int a) {
  vector<int> ans;
  for (int i = 0; i < 4; i++) {
    ans.push_back(a % 10);
    a /= 10;
  }
  return ans;
}
pair<int, int> calc(vector<int> a, vector<int> b) {
  vector<int> cnta(10), cntb(10);
  pair<int, int> ans = {0, 0};
  for (int i = 0; i < 4; i++) {
    cnta[a[i]]++;
    cntb[b[i]]++;
    if (a[i] == b[i]) {
      ans.first++;
    }
  }
  for (int i = 0; i < 10; i++) {
    if (max(cnta[i], cntb[i]) > 1) {
      return {-1, -1};
    }
    ans.second += min(cnta[i], cntb[i]);
  }
  ans.second -= ans.first;
  return ans;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<pair<int, int> > b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cin >> b[i].first >> b[i].second;
  }
  int cnt = 0;
  int ans = -1;
  for (int x = 0; x < (int)1e4 && cnt < 2; x++) {
    int f = 1;
    for (int i = 0; i < n; i++) {
      if (calc(get(a[i]), get(x)) != b[i]) {
        f = 0;
        break;
      }
    }
    if (f == 1) {
      cnt++;
      ans = x;
    }
  }
  if (cnt > 1) {
    cout << "Need more data" << endl;
  } else if (cnt == 1) {
    printf("%04d", ans);
  } else {
    cout << "Incorrect data" << endl;
  }
  return 0;
}
