#include <bits/stdc++.h>
char data[11][5];
int bull[11];
int cows[11];
char midim[5];
char answe[5];
int bb(char* a, char* b) {
  int count = 0;
  for (int i = 0; i < 4; ++i)
    if (*(a + i) == *(b + i)) ++count;
  return count;
}
int cc(char* a, char* b) {
  int count = 0;
  for (int i = 0; i < 4; ++i)
    for (int j = 0; j < 4; ++j)
      if (*(a + i) == *(b + j) && i != j) ++count;
  return count;
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; ++i) scanf("%s%d%d", data[i], &bull[i], &cows[i]);
    int count = 0;
    for (char i0 = '0'; i0 <= '9'; ++i0)
      for (char i1 = '0'; i1 <= '9'; ++i1)
        for (char i2 = '0'; i2 <= '9'; ++i2)
          for (char i3 = '0'; i3 <= '9'; ++i3) {
            if (i0 == i1 || i0 == i2 || i0 == i3 || i1 == i2 || i1 == i3 ||
                i2 == i3)
              continue;
            midim[0] = i0;
            midim[1] = i1;
            midim[2] = i2;
            midim[3] = i3;
            bool flag = true;
            for (int i = 0; i < n; ++i)
              if (bull[i] != bb(midim, data[i]) ||
                  cows[i] != cc(midim, data[i])) {
                flag = false;
                break;
              }
            if (flag) {
              strcpy(answe, midim);
              ++count;
            }
          }
    if (count == 0)
      printf("Incorrect data\n");
    else if (count == 1)
      printf("%s\n", answe);
    else
      printf("Need more data\n");
  }
  return 0;
}
