#include <bits/stdc++.h>
using namespace std;
struct tri {
  int num;
  int b;
  int k;
};
struct m {
  int a[4];
};
tri t[10];
m get(int a) {
  m b;
  for (int i = 0; i < 4; i++) {
    b.a[i] = a % 10;
    a /= 10;
  }
  return b;
}
bool correct(int a) {
  m b;
  b = get(a);
  for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 4; j++) {
      if (b.a[i] == b.a[j]) return false;
    }
  }
  return true;
}
bool check(tri a, int b) {
  m c = get(b);
  m d = get(a.num);
  int buk = 0;
  int kor = 0;
  for (int i = 0; i < 4; i++) {
    if (c.a[i] == d.a[i]) {
      buk++;
    }
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (c.a[i] == d.a[j] && i != j) {
        kor++;
      }
    }
  }
  if (a.b == buk && a.k == kor) {
    return true;
  }
  return false;
}
int main(int argc, char* const argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t[i].num >> t[i].b >> t[i].k;
  }
  int found = 0;
  int number;
  for (int i = 1; i < 9999; i++) {
    if (correct(i)) {
      bool all_ok = true;
      for (int j = 0; j < n; j++) {
        if (!check(t[j], i)) {
          all_ok = false;
        }
      }
      if (all_ok) {
        found++;
        number = i;
      }
    }
  }
  if (found == 0) {
    cout << "Incorrect data";
  } else if (found == 1) {
    m numb = get(number);
    for (int i = 3; i >= 0; i--) {
      cout << numb.a[i];
    }
  } else {
    cout << "Need more data";
  }
  return 0;
}
