#include <bits/stdc++.h>
using namespace std;
const int N = 20;
struct Node {
  int num[4];
  int a, b;
} node[N];
int ans[4];
int vis[11];
bool ok(int num) {
  memset(vis, 0, sizeof(vis));
  int t;
  for (int i = 0; i < 4; i++) {
    t = num % 10;
    if (vis[t]) {
      return false;
    }
    ans[i] = t;
    vis[t] = 1;
    num /= 10;
  }
  return true;
}
int main() {
  int n;
  char arr[5];
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%s %d %d", arr, &node[i].a, &node[i].b);
      for (int j = 0; j < 4; j++) {
        node[i].num[j] = arr[j] - '0';
      }
    }
    int cnt1, cnt2, cnt;
    cnt = 0;
    int res;
    for (int i = 1; i < 10000; i++) {
      if (ok(i)) {
        int j;
        for (j = 0; j < n; j++) {
          cnt1 = cnt2 = 0;
          for (int k = 0; k < 4; k++) {
            if (ans[k] == node[j].num[k]) {
              cnt1++;
            }
            if (vis[node[j].num[k]]) {
              cnt2++;
            }
          }
          if (cnt1 != node[j].a || cnt2 - cnt1 != node[j].b) {
            break;
          }
        }
        if (j == n) {
          res = i;
          cnt++;
        }
      }
    }
    if (cnt == 1) {
      for (int i = 0; i < 4; i++) {
        printf("%d", res % 10);
        res /= 10;
      }
      printf("\n");
    } else if (cnt > 1) {
      printf("Need more data\n");
    } else {
      printf("Incorrect data\n");
    }
  }
  return 0;
}
