#include <bits/stdc++.h>
using namespace std;
long long int n;
vector<pair<string, pair<long long int, long long int>>> v;
vector<string> res;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long int i = 0; i < n; ++i) {
    string t;
    long long int a, b;
    cin >> t >> a >> b;
    v.push_back({t, {a, b}});
  }
  for (long long int a = 0; a <= 9; ++a) {
    for (long long int b = 0; b <= 9; ++b) {
      for (long long int c = 0; c <= 9; ++c) {
        for (long long int d = 0; d <= 9; ++d) {
          if (a == b || b == c || c == d || b == d || a == c || a == d)
            continue;
          string s;
          s += char(a + '0');
          s += char(b + '0');
          s += char(c + '0');
          s += char(d + '0');
          bool ok = 1;
          for (long long int i = 0; i < n; ++i) {
            long long int bull = 0, cow = 0;
            for (long long int j = 0; j < 4; ++j) {
              if (s[j] == v[i].first[j])
                bull++;
              else if (v[i].first.find(s[j]) != string::npos)
                cow++;
            }
            if (bull != v[i].second.first || cow != v[i].second.second) {
              ok = 0;
              break;
            }
          }
          if (ok) res.push_back(s);
        }
      }
    }
  }
  if ((long long int)res.size() > 1)
    cout << "Need more data\n";
  else if (!(long long int)res.size())
    cout << "Incorrect data\n";
  else
    cout << res[0] << '\n';
  return 0;
}
