#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const double PI = 3.141592653589793;
int tab[12][2], k, i, res, j, g[12][5], n;
char t[10];
bool good(int k) {
  int t[4] = {k / 1000, (k / 100) % 10, (k / 10) % 10, k % 10};
  int i, j, r1, r2, ind, l;
  for (i = 0; i < 4; i++)
    for (j = i + 1; j < 4; j++)
      if (t[i] == t[j]) return 0;
  for (i = 0; i < n; i++) {
    r1 = r2 = 0;
    for (j = 0; j < 4; j++) {
      ind = -1;
      for (l = 0; l < 4; l++)
        if (g[i][l] == t[j]) ind = l;
      if (ind == j)
        r1++;
      else if (ind != -1)
        r2++;
    }
    if (r1 != tab[i][0] || r2 != tab[i][1]) return 0;
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s %d %d", &t, &tab[i][0], &tab[i][1]);
    for (j = 0; j < 4; j++) g[i][j] = int(t[j]) - 48;
  }
  res = 0;
  for (i = 0; i < 10000; i++)
    if (good(i)) {
      k = i;
      res++;
    }
  if (res > 1)
    printf("Need more data\n");
  else if (res == 0)
    printf("Incorrect data\n");
  else
    printf("%d%d%d%d\n", k / 1000, (k / 100) % 10, (k / 10) % 10, k % 10);
  return 0;
}
