#include <bits/stdc++.h>
using namespace std;
int n, sum, nx, ny, kx, ky, tt;
int a[11][3], ans[4];
bool pp[10], spe[10];
void prepare(int x, int y) {
  if (x == 5) {
    for (int i = 1; i <= n; i++) {
      memset(spe, 0, sizeof(spe));
      kx = y;
      ky = a[i][0];
      nx = 0;
      ny = 0;
      for (int j = 1; j <= 4; j++) {
        if (spe[kx % 10]) ++ny;
        if (spe[ky % 10]) ++ny;
        spe[kx % 10] = true;
        spe[ky % 10] = true;
        if (kx % 10 == ky % 10) ++nx;
        kx = kx / 10;
        ky = ky / 10;
      }
      if ((nx != a[i][1]) || (ny != a[i][2])) return;
    }
    ++sum;
    kx = y;
    for (int i = 3; i >= 0; i--) {
      ans[i] = kx % 10;
      kx = kx / 10;
    }
    return;
  }
  for (int i = 0; i <= 9; i++)
    if (!pp[i]) {
      pp[i] = true;
      prepare(x + 1, y * 10 + i);
      pp[i] = false;
    }
}
void solve() {
  prepare(1, 0);
  if (sum == 0)
    cout << "Incorrect data";
  else if (sum == 1)
    cout << ans[0] << ans[1] << ans[2] << ans[3];
  else
    cout << "Need more data";
}
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);
}
int main() {
  init();
  solve();
  return 0;
}
