#include <bits/stdc++.h>
using namespace std;
long long fact[1000001];
int main() {
  int n;
  cin >> n;
  pair<string, pair<int, int>> check[n];
  for (int i = 0; i < n; i++)
    cin >> check[i].first >> check[i].second.first >> check[i].second.second;
  int cnt = 0;
  string ans;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        for (int l = 0; l < 10; l++) {
          string s;
          s += i + '0';
          s += j + '0';
          s += k + '0';
          s += l + '0';
          set<int> st;
          st.insert(i);
          st.insert(j);
          st.insert(k);
          st.insert(l);
          if (st.size() < 4) continue;
          bool fl = true;
          for (int m = 0; m < n; m++) {
            int bulls = 0, cows = 0, cow[10] = {};
            string ss = check[m].first;
            for (int o = 0; o < s.size(); o++) {
              if (s[o] == ss[o])
                bulls++;
              else {
                cow[s[o] - '0']++;
                cow[ss[o] - '0']++;
              }
            }
            for (int i = 0; i < 10; i++)
              if (cow[i] > 1) cows++;
            if (bulls != check[m].second.first ||
                cows != check[m].second.second)
              fl = false;
          }
          if (fl) cnt++, ans = s;
        }
      }
    }
  }
  if (cnt == 0)
    cout << "Incorrect data" << endl;
  else if (cnt > 1)
    cout << "Need more data" << endl;
  else
    cout << ans << endl;
}
