#include <bits/stdc++.h>
using namespace std;
string s[15];
int b[15], c[15];
bool check(string s) {
  for (int i = 0; i < 4; i++)
    for (int j = i + 1; j < 4; j++)
      if (s[i] == s[j]) return 0;
  return 1;
}
int bull(string t, string s) {
  int cnt = 0;
  for (int i = 0; i < 4; i++)
    if (s[i] == t[i]) cnt++;
  return cnt;
}
int cow(string t, string s) {
  int cnt = 0;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
      if (s[i] == t[j]) cnt++;
  return cnt;
}
int main() {
  int n, cnt = 0;
  string ans;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i] >> b[i] >> c[i];
  for (int i = 123; i <= 9876; i++) {
    string t;
    stringstream ss;
    ss << i;
    ss >> t;
    if (t.size() < 4) t = "0" + t;
    if (check(t) == 0) continue;
    int f = 0;
    for (int j = 0; j < n; j++) {
      if (bull(s[j], t) != b[j]) {
        f = 1;
        break;
      }
      if (cow(s[j], t) - bull(s[j], t) != c[j]) {
        f = 1;
        break;
      }
    }
    if (f == 0) cnt++, ans = t;
  }
  if (cnt == 1)
    cout << ans;
  else if (cnt > 1)
    cout << "Need more data";
  else
    cout << "Incorrect data";
}
