#include <bits/stdc++.h>
using namespace std;
int num[11];
int sa[11];
int sb[11];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d%d", &num[i], &sa[i], &sb[i]);
  int can = -1;
  for (int i = 0; i <= 9999; i++) {
    int x = i;
    int a = x / 1000, b = (x / 100) % 10, c = (x / 10) % 10, d = x % 10;
    if (a == b || a == c || a == d || b == c || b == d || c == d) continue;
    int ok = 0;
    for (int j = 0; j < n; j++) {
      x = num[j];
      int a1 = x / 1000, b1 = (x / 100) % 10, c1 = (x / 10) % 10, d1 = x % 10;
      int s1 = 0, s2 = 0;
      if (a == a1) s1++;
      if (b == b1) s1++;
      if (c == c1) s1++;
      if (d == d1) s1++;
      if (a == b1) s2++;
      if (a == c1) s2++;
      if (a == d1) s2++;
      if (b == a1) s2++;
      if (b == c1) s2++;
      if (b == d1) s2++;
      if (c == a1) s2++;
      if (c == b1) s2++;
      if (c == d1) s2++;
      if (d == a1) s2++;
      if (d == c1) s2++;
      if (d == b1) s2++;
      if (sa[j] == 4 || (sa[j] == 3 && sb[j] == 1)) {
        printf("Incorrect data\n");
        return 0;
      }
      if (s1 == sa[j] && s2 == sb[j]) ok++;
    }
    if (ok == n && can != -1) {
      printf("Need more data\n");
      return 0;
    } else if (ok == n)
      can = i;
  }
  if (can == -1)
    printf("Incorrect data\n");
  else
    printf("%.4d\n", can);
  return 0;
}
