#include <bits/stdc++.h>
using namespace std;
int main() {
  string str = "";
  vector<string> v;
  for (char a = '0'; a <= '9'; a++)
    for (char b = '0'; b <= '9'; b++)
      for (char c = '0'; c <= '9'; c++)
        for (char d = '0'; d <= '9'; d++) {
          string t = "";
          if (a == b || a == c || a == d || b == c || b == d || c == d)
            continue;
          t += a;
          t += b;
          t += c;
          t += d;
          v.push_back(t);
        }
  int n = 0, ans = 0;
  string arr[10];
  int bc[10][2];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    cin >> bc[i][0] >> bc[i][1];
  }
  for (int i = 0; i < (int)v.size(); i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      bool vis[100] = {0};
      vis[arr[j][0]] = vis[arr[j][1]] = vis[arr[j][2]] = vis[arr[j][3]] = 1;
      int x = (v[i][0] == arr[j][0]) + (v[i][1] == arr[j][1]) +
              (v[i][2] == arr[j][2]) + (v[i][3] == arr[j][3]);
      int y = (vis[v[i][0]] && !(v[i][0] == arr[j][0])) +
              (vis[v[i][1]] && !(v[i][1] == arr[j][1])) +
              (vis[v[i][2]] && !(v[i][2] == arr[j][2])) +
              (vis[v[i][3]] && !(v[i][3] == arr[j][3]));
      cnt += (bc[j][0] == x && bc[j][1] == y);
    }
    if (cnt == n) str = v[i], ans++;
  }
  if (ans == 1)
    cout << str;
  else if (!ans)
    cout << "Incorrect data";
  else
    cout << "Need more data";
  return 0;
}
