#include <bits/stdc++.h>
using namespace std;
int dcmp(double a, double b) {
  return fabs(a - b) <= 0.0000000001 ? 0 : (a > b) ? 1 : -1;
}
vector<pair<string, pair<int, int> > > v;
string check(int n) {
  string r = "";
  while (n > 0) {
    r = (char)(n % 10 + '0') + r;
    n /= 10;
  }
  if (((int)(r).size()) == 3) r = "0" + r;
  for (int i = 0; i < 4; i++)
    for (int j = i + 1; j < 4; j++)
      if (r[i] == r[j]) return "#";
  return r;
}
bool g(string num, string gus, int h, int c) {
  int t = 0, u = 0;
  for (int i = 0; i < 4; i++)
    if (num[i] == gus[i]) t++;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (i != j && num[i] == gus[j]) u++;
    }
  }
  if (u == c && t == h) return 1;
  return 0;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string st;
    int h, c;
    cin >> st >> h >> c;
    v.push_back(make_pair(st, make_pair(h, c)));
  }
  int c = 0;
  string ans, num;
  for (int i = 123; i < 10000; i++) {
    ans = check(i);
    if (ans == "#") continue;
    int fl = 1;
    for (int j = 0; j < n; j++) {
      if (!g(ans, v[j].first, v[j].second.first, v[j].second.second)) fl = 0;
    }
    if (fl) {
      c++;
      num = ans;
    }
  }
  if (c == 1)
    cout << num << endl;
  else if (c == 0)
    cout << "Incorrect data\n";
  else
    cout << "Need more data\n";
}
