#include <bits/stdc++.h>
using namespace std;
stringstream ss;
set<int> Set;
string s[181], s1;
int a[181], b[181], n, i, z, kol, ans;
bool x;
pair<int, int> get(string s1, string s2) {
  int i, kol1 = 0, kol2 = 0;
  for (i = 0; i < s1.size(); i++)
    if (s1[i] == s2[i])
      kol1++;
    else if (s2.find(s1[i]) != string::npos)
      kol2++;
  return make_pair(kol1, kol2);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (i = 1; i <= n; i++) cin >> s[i] >> a[i] >> b[i];
  for (z = 0; z <= 9999; z++) {
    ss.clear();
    ss << z;
    ss >> s1;
    while (s1.size() < 4) s1 = "0" + s1;
    Set.clear();
    for (i = 0; i < 4; i++) Set.insert(s1[i] - 48);
    if (Set.size() < 4) continue;
    x = true;
    for (i = 1; i <= n; i++)
      if (get(s1, s[i]) != make_pair(a[i], b[i])) x = false;
    if (x) {
      kol++;
      ans = z;
    }
  }
  if (kol == 0) {
    cout << "Incorrect data" << '\n';
    return 0;
  }
  if (kol == 1) {
    if (ans < 1000) cout << "0";
    cout << ans << '\n';
    return 0;
  }
  cout << "Need more data" << '\n';
  return 0;
}
