#include <bits/stdc++.h>
using namespace std;
int const mod = 1000000007;
inline bool check(string x, string y, int a, int b) {
  int c = 0, v = 0;
  for (int i = 0; i < 4; i++)
    if (x[i] == y[i]) {
      c++;
      v--;
    }
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
      if (x[i] == y[j]) v++;
  return a == c && b == v;
}
int main() {
  int n;
  cin >> n;
  list<string> x;
  for (int i = 0; i <= 9; i++)
    for (int j = 0; j <= 9; j++)
      if (i != j)
        for (int k = 0; k <= 9; k++)
          if (i != k && j != k)
            for (int l = 0; l <= 9; l++)
              if (i != l && j != l && k != l) {
                string s = "";
                s += char('0' + i);
                s += char('0' + j);
                s += char('0' + k);
                s += char('0' + l);
                x.push_back(s);
              }
  for (int i = 0; i < n; i++) {
    string s;
    int a, b;
    cin >> s >> a >> b;
    for (auto it = x.begin(); it != x.end(); it++) {
      if (!check(*it, s, a, b)) x.erase(it--);
    }
  }
  if (x.size() == 0)
    cout << "Incorrect data\n";
  else if (x.size() == 1)
    cout << *x.begin() << "\n";
  else
    cout << "Need more data\n";
}
