#include <bits/stdc++.h>
using namespace std;
inline void EnableFileIO(const string& fileName) {
  if (fileName.empty()) return;
  freopen((fileName + ".in").c_str(), "r", stdin);
  freopen((fileName + ".out").c_str(), "w", stdout);
  return;
}
const int INF = (1 << 30) - 1;
const long long LINF = (1LL << 61) - 1;
const double EPS = 1e-10;
const int N = 20;
int n;
int num[N], in[N], ap[N];
int appear[N][N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  EnableFileIO("");
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[i] >> in[i] >> ap[i];
    for (int j = 0, t = num[i]; j < 4; j++, t /= 10) {
      appear[i][t % 10] = 1;
    }
  }
  vector<int> ans;
  ans.clear();
  for (int i = 0; i < 10000; i++) {
    set<int> st;
    for (int j = 0, t = i; j < 4; j++, t /= 10) st.insert(t % 10);
    if (st.size() != 4) continue;
    bool flag = true;
    for (int j = 0; j < n; j++) {
      int a = 0, b = 0;
      for (int k = 0, t = i, p = num[j]; k < 4; k++, t /= 10, p /= 10) {
        if (t % 10 == p % 10) {
          a++;
        } else if (appear[j][t % 10]) {
          b++;
        }
      }
      if (a != in[j] || b != ap[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans.push_back(i);
    }
  }
  if (ans.empty()) {
    cout << "Incorrect data" << endl;
  } else if (ans.size() > 1) {
    cout << "Need more data" << endl;
  } else {
    if (ans[0] < 1000) cout << 0;
    cout << ans[0] << endl;
  }
  return 0;
}
