#include <bits/stdc++.h>
using namespace std;
int rank[1000];
int a[20], b[20];
int snum[4];
char in[20][20];
int site[20][10];
int ANS[4];
int n;
int check(int a1, int a2, int a3, int a4) {
  for (int i = 0; i < n; i++) {
    int an = 0, bn = 0;
    if (site[i][a1] == 0)
      an++;
    else if (site[i][a1] != -1)
      bn++;
    if (site[i][a2] == 1)
      an++;
    else if (site[i][a2] != -1)
      bn++;
    if (site[i][a3] == 2)
      an++;
    else if (site[i][a3] != -1)
      bn++;
    if (site[i][a4] == 3)
      an++;
    else if (site[i][a4] != -1)
      bn++;
    if (an != a[i] || bn != b[i]) return 0;
  }
  ANS[0] = a1;
  ANS[1] = a2;
  ANS[2] = a3;
  ANS[3] = a4;
  return 1;
}
int main() {
  while (scanf("%d", &n) == 1) {
    memset(site, -1, sizeof(site));
    for (int i = 0; i < n; i++) {
      scanf("%s%d%d", in[i], &a[i], &b[i]);
      for (int j = 0; j < 4; j++) {
        site[i][in[i][j] - '0'] = j;
      }
    }
    int ans = 0;
    for (int a1 = 0; a1 < 10; a1++)
      for (int a2 = 0; a2 < 10; a2++)
        for (int a3 = 0; a3 < 10; a3++)
          for (int a4 = 0; a4 < 10; a4++) {
            if (a1 == a2 || a1 == a3 || a1 == a4 || a2 == a3 || a2 == a4 ||
                a3 == a4)
              continue;
            if (check(a1, a2, a3, a4)) ans++;
          }
    if (ans > 1)
      printf("Need more data\n");
    else if (ans == 1) {
      printf("%d", ANS[0]);
      printf("%d", ANS[1]);
      printf("%d", ANS[2]);
      printf("%d\n", ANS[3]);
    } else
      printf("Incorrect data\n");
  }
  return 0;
}
