#include <bits/stdc++.h>
using namespace std;
const int N = 12;
void solve() {
  long long int n;
  cin >> n;
  string s[n];
  long long int a[n], b[n];
  for (long long int i = 0; i < n; i++) {
    cin >> s[i] >> a[i] >> b[i];
  }
  vector<string> ans;
  for (long long int i = 100; i <= 9999; i++) {
    string t = to_string(i);
    while (t.size() < 4) t = '0' + t;
    long long int fre[10] = {0};
    for (char c : t) fre[c - '0']++;
    long long int chk = 1;
    for (long long int j = 0; j < 10; j++) {
      if (fre[j] > 1) chk = 0;
    }
    if (chk) {
      long long int pos[4];
      memset(pos, -1, sizeof(pos));
      for (long long int j = 0; j < n; j++) {
        long long int x = 0, y = 0;
        for (long long int k = 0; k < 4; k++) {
          if (s[j][k] == t[k] && (pos[k] == -1 || pos[k] == s[j][k] - '0'))
            x++;
          else if (s[j][k] != t[k]) {
            if (fre[s[j][k] - '0']) y++;
          }
        }
        if (x == a[j] && y == b[j]) {
          for (long long int k = 0; k < 4; k++) {
            if (s[j][k] == t[k] && (pos[k] == -1 || pos[k] == s[j][k] - '0')) {
              pos[k] = s[j][k] - '0';
            }
          }
        } else {
          chk = 0;
          break;
        }
      }
    }
    if (chk) ans.push_back(t);
  }
  if (ans.size() == 1)
    cout << ans[0];
  else if (ans.size() > 1)
    cout << "Need more data";
  else
    cout << "Incorrect data";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
}
