#include <bits/stdc++.h>
using namespace std;
struct Request {
  string st;
  int a, b;
};
const int MAXN = 10;
Request ra[MAXN];
string IntToString(int val, int len) {
  string ret = "";
  for (int i = 0; i < len; i++, val /= 10) ret = (char)(val % 10 + '0') + ret;
  for (int i = 0; i < len; i++)
    for (int j = i + 1; j < len; j++)
      if (ret[i] == ret[j]) return "";
  return ret;
}
bool Check(string guess, Request rq) {
  int cnta, cntb;
  cnta = cntb = 0;
  for (int i = 0; i < 4; i++)
    if (guess[i] == rq.st[i]) cnta++;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
      if (i != j && guess[i] == rq.st[j]) cntb++;
  return (cnta == rq.a && cntb == rq.b);
}
int main() {
  int n;
  int ans = 0;
  string ansst;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ra[i].st >> ra[i].a >> ra[i].b;
  for (int i = 0; i < 10000; i++) {
    string guess = IntToString(i, 4);
    if (guess == "") continue;
    int okay = true;
    for (int j = 0; j < n; j++)
      if (!Check(guess, ra[j])) {
        okay = false;
        break;
      }
    if (okay) ans++, ansst = guess;
  }
  if (ans == 0)
    cout << "Incorrect data" << endl;
  else if (ans == 1)
    cout << ansst << endl;
  else
    cout << "Need more data" << endl;
  return 0;
}
