#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
bool dif(string s) {
  vector<bool> d(10);
  for (int i = 0; i < int((s).size()); i++) d[s[i] - '0'] = true;
  int c = 0;
  for (int i = 0; i < int((d).size()); i++)
    if (d[i]) ++c;
  return c == s.size();
}
int bok(string s1, string s2) {
  int c = 0;
  for (int i = 0; i < int((s1).size()); i++)
    if (s1[i] == s2[i]) ++c;
  return c;
}
int kok(string s1, string s2) {
  vector<bool> d1(10);
  for (int i = 0; i < int((s1).size()); i++) d1[s1[i] - '0'] = true;
  vector<bool> d2(10);
  for (int i = 0; i < int((s2).size()); i++) d2[s2[i] - '0'] = true;
  int c = 0;
  for (int i = 0; i < int((d1).size()); i++)
    if (d1[i] && d2[i]) ++c;
  return c - bok(s1, s2);
}
int main() {
  int n;
  cin >> n;
  vector<string> pr(n);
  vector<int> b(n), k(n);
  for (int i = 0; i < int((pr).size()); i++) cin >> pr[i] >> b[i] >> k[i];
  int c = 0, what;
  for (int j = 123; j < 9999; ++j) {
    ostringstream os;
    os << j;
    istringstream is(os.str());
    string sj;
    is >> sj;
    if (sj.size() == 3) sj.insert(sj.begin(), '0');
    if (!dif(sj)) continue;
    int t = 0;
    for (; t < n; ++t)
      if (bok(sj, pr[t]) != b[t]) break;
    if (t != n) continue;
    t = 0;
    for (; t < n; ++t)
      if (kok(sj, pr[t]) != k[t]) break;
    if (t != n) continue;
    ++c;
    what = j;
  }
  if (c > 1)
    cout << "Need more data\n";
  else if (c == 1) {
    if (what < 1000) cout << '0';
    cout << what << endl;
  } else
    cout << "Incorrect data\n";
  return 0;
}
