#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const long long INF = 1e18 + 99;
const long long MOD = 1e9 + 7;
inline long long two(long long n) { return 1 << n; }
inline void set_bit(long long& n, long long b) { n |= two(b); }
inline void unset_bit(long long& n, long long b) { n &= ~two(b); }
inline long long last_bit(long long n) { return n & (-n); }
inline long long ones(long long n) {
  long long res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
template <class T>
void chmax(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void chmin(T& a, const T& b) {
  a = min(a, b);
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <typename T>
T exp(T b, T p) {
  T x = 1;
  while (p) {
    if (p & 1) x = (x * b);
    b = (b * b);
    p = p >> 1;
  }
  return x;
}
void boostIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long modpow(long long a, long long b) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
long long save[4], taken[10], numbers[12], bull[12], caw[12], n, gen[4],
    ans = 0;
bool Correct(long long idx) {
  long long nm = numbers[idx], b = 0, c = 0;
  for (long long i = 3; i >= 0; i--, nm /= 10) {
    long long md = nm % 10;
    if (md == gen[i]) b++;
    if (taken[md]) c++;
  }
  c -= b;
  return b == bull[idx] and c == caw[idx];
}
void Gen(long long lvl) {
  if (lvl == 4) {
    for (long long i = 0; i < (n); i++)
      if (!Correct(i)) return;
    ans++;
    for (long long i = 0; i < (4); i++) save[i] = gen[i];
  } else {
    for (long long i = 0; i < (10); i++)
      if (!taken[i]) {
        taken[i] = true;
        gen[lvl] = i;
        Gen(lvl + 1);
        taken[i] = false;
      }
  }
}
int32_t main() {
  boostIO();
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> numbers[i] >> bull[i] >> caw[i];
  }
  Gen(0);
  if (ans == 0)
    cout << "Incorrect data\n";
  else if (ans == 1) {
    for (long long i = 0; i < 4; i++) cout << save[i];
    cout << "\n";
  } else
    cout << "Need more data\n";
  return 0;
}
