#include <bits/stdc++.h>
using namespace std;
int n, k;
int A[100], B[100];
string S[100];
vector<string> R;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i] >> A[i] >> B[i];
  }
  for (int i = 0; i < 10000; i++) {
    string s;
    stringstream ss;
    ss << i;
    ss >> s;
    while (s.size() < 4) s = '0' + s;
    if (s[0] == '0' && s[1] == 0) continue;
    bool ok = true;
    string t = s;
    sort(t.begin(), t.end());
    for (int j = 1; j < 4; j++)
      if (t[j] == t[j - 1]) ok = false;
    if (ok) {
      ok = true;
      for (int l = 0; l < n; l++) {
        int x = 0, y = 0;
        for (int j = 0; j < 4; j++) {
          int f = -1;
          for (int k = 0; k < 4; k++)
            if (s[k] == S[l][j]) f = k;
          if (f == j)
            x++;
          else if (f != -1)
            y++;
        }
        if (x != A[l] || y != B[l]) ok = false;
      }
      if (ok) R.push_back(s);
    }
  }
  if (R.empty())
    cout << "Incorrect data" << endl;
  else if (R.size() == 1)
    cout << R[0] << endl;
  else
    cout << "Need more data" << endl;
  cin >> n;
  return 0;
}
