#include <bits/stdc++.h>
using namespace std;
bool check(string n) {
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
      if (i != j && n[i] == n[j]) return false;
  return true;
}
int main(void) {
  int n;
  cin >> n;
  string E[10];
  int X[10], Y[10];
  for (int i = 0; i < n; i++) {
    int ei;
    cin >> ei >> X[i] >> Y[i];
    ostringstream os;
    os << setw(4) << setfill('0') << ei;
    E[i] = os.str();
  }
  int count = 0;
  string answer = "";
  for (int m = 0; m < 10000; m++) {
    ostringstream os;
    os << setw(4) << setfill('0') << m;
    string t = os.str();
    if (check(t) == false) continue;
    bool ok1 = true;
    for (int i = 0; i < n; i++) {
      string e = E[i];
      string u = t;
      int x = 0, y = 0;
      for (int j = 0; j < 4; j++)
        if (e[j] == u[j]) x++;
      for (int j = 0; j < 4; j++)
        if (e[j] != u[j] && e.find(u[j]) != string::npos) y++;
      if (X[i] != x || Y[i] != y) {
        ok1 = false;
      }
    }
    if (ok1) {
      answer = t;
      count++;
    }
  }
  if (count == 0) answer = "Incorrect data";
  if (count > 1) answer = "Need more data";
  cout << answer << endl;
  return 0;
}
