#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, cnt = 0;
  cin >> n;
  int x[n + 5], y[n + 5];
  vector<int> chk(10006, 0);
  for (int i = 0; i < 10000; i++) {
    set<int> dig;
    int tmp = i;
    while (tmp) {
      dig.insert(tmp % 10);
      tmp /= 10;
    }
    if (dig.size() == 4 ||
        (dig.size() == 3 && dig.find(0) == dig.end() && i > 100 && i < 1000)) {
      chk[i] = 1;
      cnt++;
    }
  }
  for (int i = 0; i < n; i++) {
    string nm;
    cin >> nm >> x[i] >> y[i];
    for (int j = 0; j < 10000; j++) {
      if (chk[j] == 1) {
        string s = to_string(j);
        while (s.size() != 4) {
          s = '0' + s;
        }
        int match = 0;
        set<char> got1, got2;
        for (int k = 0; k < 4; k++) {
          if (nm[k] == s[k]) {
            match++;
          } else {
            got1.insert(nm[k]);
            got2.insert(s[k]);
          }
        }
        if (match != x[i]) {
          chk[j] = 0;
          continue;
        }
        match = 0;
        for (auto x : got1) {
          if (got2.find(x) != got2.end()) {
            match++;
          }
        }
        if (match != y[i]) {
          chk[j] = 0;
          continue;
        }
      }
    }
  }
  int cntt = 0;
  for (int i = 0; i < 10000; i++) {
    if (chk[i] == 1) {
      cntt++;
    }
  }
  if (cntt == 0) {
    cout << "Incorrect data" << endl;
  } else if (cntt > 1) {
    cout << "Need more data";
  } else {
    for (int i = 0; i < 10000; i++) {
      if (chk[i] == 1) {
        string ans = to_string(i);
        while (ans.size() != 4) {
          ans = '0' + ans;
        }
        cout << ans;
      }
    }
  }
  cout << endl;
  return 0;
}
