#include <bits/stdc++.h>
bool check(const char* t, const char* a, int b, int c) {
  for (int i(0); t[i]; ++i) {
    for (int j(0); a[j]; ++j) {
      b -= (i == j) & (t[i] == a[i]);
      c -= (i != j) & (t[i] == a[j]);
    }
  }
  return b == 0 && c == 0;
}
int main() {
  int n;
  char a[10][5];
  int b[10];
  int c[10];
  char w[5] = "";
  char r[5];
  int t(0);
  std::scanf("%d", &n);
  for (int i(0); i < n; ++i) std::scanf("%s%d%d", a[i], b + i, c + i);
  for (w[0] = '0'; w[0] <= '9'; ++w[0]) {
    for (w[1] = '0'; w[1] <= '9'; ++w[1]) {
      if (w[0] == w[1]) continue;
      for (w[2] = '0'; w[2] <= '9'; ++w[2]) {
        if (w[0] == w[2] || w[1] == w[2]) continue;
        for (w[3] = '0'; w[3] <= '9'; ++w[3]) {
          if (w[0] == w[3] || w[1] == w[3] || w[2] == w[3]) continue;
          for (int i(0); i < n; ++i) {
            if (!check(w, a[i], b[i], c[i])) goto N;
          }
          if (t++ < 1) std::strcpy(r, w);
        N:;
        }
      }
    }
  }
  if (t == 1)
    std::puts(r);
  else
    std::puts(1 < t ? "Need more data" : "Incorrect data");
  return 0;
}
