#include <bits/stdc++.h>
using namespace std;
string g[11];
int n, c[11], t[11];
string st;
bool ch(string s) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int xs = 0, ys = 0;
    string guess = g[i];
    for (int k = 0; k < 4; k++) {
      if ((int)guess.find(s[k]) != -1) ys++;
    }
    for (int k = 0; k < 4; k++) {
      if (s[k] == guess[k]) {
        xs++;
        ys--;
      }
    }
    if (xs == c[i] && ys == t[i]) cnt++;
  }
  return (cnt == n);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> g[i] >> c[i] >> t[i];
  }
  int res = 0;
  for (int i = 0; i <= 9999; i++) {
    string s = to_string(i);
    while (s.size() < 4) {
      s.insert(s.begin(), '0');
    }
    set<char> test;
    for (int j = 0; j < s.size(); j++) {
      test.insert(s[j]);
    }
    if (test.size() == 4) {
      bool ans = ch(s);
      if (ans) {
        res++;
        st = s;
      }
    }
  }
  if (res == 0) cout << "Incorrect data";
  if (res > 1)
    cout << "Need more data";
  else
    cout << st;
  return 0;
}
