#include <bits/stdc++.h>
using namespace std;
int n;
char str[15][10];
int bull[15], cow[15];
bool flag[15];
int main() {
  FILE *in = stdin;
  int c, c2;
  fscanf(in, "%d", &n);
  for (c = 0; c < n; c++) fscanf(in, "%s%d%d", str[c], &bull[c], &cow[c]);
  int c3;
  int cnt = 0;
  int ret;
  for (c = 0; c < 10000; c++) {
    if (cnt > 1) break;
    memset(flag, 0, sizeof(flag));
    int num = c;
    for (c2 = 0; c2 < 4; c2++) {
      if (flag[num % 10]) break;
      flag[num % 10] = 1;
      num /= 10;
    }
    if (c2 < 4) continue;
    int r1 = 0, r2 = 0;
    for (c2 = 0; c2 < n; c2++) {
      num = c;
      r1 = r2 = 0;
      for (c3 = 3; c3 >= 0; c3--, num /= 10) {
        if (str[c2][c3] - '0' == num % 10) r2++;
        if (flag[str[c2][c3] - '0']) r1++;
      }
      if ((r2 != bull[c2]) || ((r1 - r2) != cow[c2])) break;
    }
    if (c2 == n) {
      cnt++;
      ret = c;
    }
  }
  if (cnt == 0)
    printf("Incorrect data\n");
  else if (cnt > 1)
    printf("Need more data\n");
  else {
    if (ret < 1000) printf("0");
    printf("%d\n", ret);
  }
  return 0;
}
