#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
int n, a[10][4], x[10], y[10], c[4];
void gao(int m) {
  if (m == 4) {
    for (int i = 0; i < n; i++) {
      int cnt = 0, sum = 0;
      for (int k = 0; k < 4; k++)
        if (a[i][k] == c[k]) cnt++;
      if (cnt != x[i]) return;
      for (int u = 0; u < 10; u++)
        sum += min(count(a[i], a[i] + 4, u), count(c, c + 4, u));
      if (sum - cnt != y[i]) return;
    }
    ans.push_back(0);
    for (int i = 0; i < 4; i++) ans.back() = ans.back() * 10 + c[i];
  } else {
    for (int u = 0; u < 10; u++)
      if (find(c, c + m, c[m] = u) == c + m) gao(m + 1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < 4; k++) scanf("%1d", &a[i][k]);
    scanf("%d%d", &x[i], &y[i]);
  }
  gao(0);
  if (ans.size() >= 2) return puts("Need more data");
  if (ans.size() == 0) return puts("Incorrect data");
  printf("%04d\n", ans[0]);
}
