#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > arr[15];
int n;
bool check(int x, int y, int bulls, int cows) {
  int cnt1[10] = {0}, cnt2[10] = {0};
  int b = 0, c = 0;
  for (int i = 0; i < 4; i++) {
    int aa = x % 10, bb = y % 10;
    x /= 10, y /= 10;
    if (aa == bb)
      b++;
    else
      cnt1[aa]++, cnt2[bb]++;
  }
  for (int i = 0; i < 10; i++) c += min(cnt1[i], cnt2[i]);
  return (bulls == b && cows == c);
}
int valid(int guess) {
  int cnt[10] = {0};
  int temp = guess;
  for (int i = 0; i < 4; i++) {
    cnt[temp % 10]++;
    temp /= 10;
  }
  for (int i = 0; i < 10; i++)
    if (cnt[i] > 1) return 0;
  for (int i = 0; i < n; i++)
    if (check(guess, arr[i].first, arr[i].second.first, arr[i].second.second) ==
        0)
      return 0;
  return 1;
}
int main() {
  vector<int> ans;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i].first >> arr[i].second.first >> arr[i].second.second;
  for (int i = 123; i <= 9876; i++)
    if (valid(i)) ans.push_back(i);
  if (ans.size() == 0)
    cout << "Incorrect data\n";
  else if (ans.size() > 1)
    cout << "Need more data\n";
  else
    printf("%04d\n", ans[0]);
  return 0;
}
