#include <bits/stdc++.h>
using namespace std;
bool ok[10001];
char s[15];
char p[15];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 10000; i++) ok[i] = true;
  for (int i = 0; i < n; i++) {
    int b, c;
    scanf("%s %d %d", s, &b, &c);
    for (int j = 0; j < 10000; j++) {
      if (ok[j]) {
        int bb = b;
        int cc = c;
        int x = j;
        bool good = true;
        for (int t = 0; t < 4; t++) {
          p[3 - t] = x % 10 + '0';
          x /= 10;
        }
        for (int t = 0; t < 4; t++)
          for (int m = t + 1; m < 4; m++)
            if (p[t] == p[m]) good = false;
        for (int t = 0; t < 4; t++)
          if (p[t] == s[t]) bb--;
        for (int t = 0; t < 4; t++)
          for (int m = 0; m < 4; m++)
            if (t != m && s[t] == p[m]) cc--;
        if (bb || cc) good = false;
        if (!good) ok[j] = false;
      }
    }
  }
  int total = 0;
  int ans;
  for (int i = 0; i < 10000; i++)
    if (ok[i]) {
      total++;
      ans = i;
    }
  if (total > 1)
    printf("Need more data\n");
  else if (total == 0)
    printf("Incorrect data\n");
  else
    printf("%04d\n", ans);
  return 0;
}
