#include <bits/stdc++.h>
using namespace std;
int t[4];
int p[4];
const int nmax = 10000;
bool can[nmax];
void g(int x) {
  memset(t, 0, sizeof(t));
  int i = 0;
  while (x) {
    t[i] = x % 10;
    x /= 10;
    ++i;
  }
}
int main() {
  memset(can, -1, sizeof(can));
  for (int i = 0; i < nmax; ++i) {
    g(i);
    set<int> s(t, t + 4);
    can[i] = (int)s.size() == 4;
  }
  int n;
  scanf("%d", &n);
  int x, b, c;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d", &x, &b, &c);
    for (int j = 0; j < nmax; ++j) {
      if (can[j]) {
        g(x);
        memcpy(p, t, sizeof(t));
        g(j);
        int tb = 0;
        int tc = 0;
        for (int k = 0; k < 4; ++k) {
          if (t[k] == p[k]) {
            ++tb;
            t[k] = -1;
            p[k] = -1;
          }
        }
        for (int k1 = 0; k1 < 4; ++k1) {
          if (t[k1] == -1) {
            continue;
          }
          for (int k2 = 0; k2 < 4; ++k2) {
            if (t[k1] == p[k2]) {
              ++tc;
              t[k1] = -1;
              p[k2] = -1;
              break;
            }
          }
        }
        if (tb != b || tc != c) {
          can[j] = false;
        }
      }
    }
  }
  int ind = -1;
  int cnt = 0;
  for (int i = 0; i < nmax; ++i) {
    if (can[i]) {
      ind = i;
      ++cnt;
    }
  }
  if (cnt == 0) {
    puts("Incorrect data");
    return 0;
  }
  if (cnt > 1) {
    puts("Need more data");
    return 0;
  }
  printf("%04d\n", ind);
  return 0;
}
