#include <bits/stdc++.h>
using namespace std;
int cnt, n, bull[10], cow[10];
bool vi[20];
char num[10], ans[10];
char data[20][20];
bool check() {
  int a = 0, b = 0;
  bool vis[10] = {0};
  for (int i = 0; i < 4; ++i) vis[num[i] - '0'] = 1;
  for (int i = 0; i < n; ++i) {
    a = 0, b = 0;
    for (int j = 0; j < 4; ++j) {
      if (vis[data[i][j] - '0']) ++b;
      if (data[i][j] == num[j]) ++a;
    }
    b -= a;
    if (a != bull[i] || b != cow[i]) return false;
  }
  return true;
}
void dfs(int h) {
  if (h == 4) {
    num[4] = '\0';
    if (check()) ++cnt, strcpy(ans, num);
    return;
  }
  for (int i = 0; i < 10; ++i)
    if (!vi[i]) {
      vi[i] = 1;
      num[h] = '0' + i;
      dfs(h + 1);
      vi[i] = 0;
    }
}
int main() {
  while (scanf("%d", &n) == 1) {
    cnt = 0;
    for (int i = 0; i < n; ++i) scanf("%s%d%d", data[i], &bull[i], &cow[i]);
    memset(vi, 0, sizeof(vi));
    dfs(0);
    if (cnt == 0)
      printf("Incorrect data\n");
    else if (cnt == 1)
      ans[4] = '\0', printf("%s\n", ans);
    else
      printf("Need more data\n");
  }
  return 0;
}
