#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > numr;
vector<long long> cow, bull;
bool checknum(vector<long long>& com) {
  long long n = numr.size();
  for (long long i = 0; i < n; ++i) {
    vector<long long> num = numr[i];
    long long c = 0, b = 0;
    set<long long> common;
    for (long long j = 0; j < 4; ++j) {
      common.insert(num[j]);
      if (num[j] == com[j]) {
        ++b;
      }
    }
    for (long long j = 0; j < 4; ++j) {
      common.erase(com[j]);
    }
    c = (4 - common.size()) - b;
    if (c != cow[i] || b != bull[i]) {
      return 0;
    }
  }
  return 1;
}
void play() {
  long long n;
  cin >> n;
  vector<long long> num;
  cow.assign(n, 0);
  bull.assign(n, 0);
  char c;
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < 4; ++j) {
      cin >> c;
      num.push_back(c - '0');
    }
    numr.push_back(num);
    num.clear();
    cin >> bull[i];
    cin >> cow[i];
  }
  vector<long long> res;
  bool found = 0;
  vector<long long> arr;
  for (long long i = 0; i < 10; ++i) {
    arr.push_back(i);
    for (long long j = 0; j < 10; ++j) {
      if (j == i) {
        continue;
      }
      arr.push_back(j);
      for (long long k = 0; k < 10; ++k) {
        if (k == j || k == i) {
          continue;
        }
        arr.push_back(k);
        for (long long l = 0; l < 10; ++l) {
          if (l == k || l == j || l == i) {
            continue;
          }
          arr.push_back(l);
          if (checknum(arr)) {
            if (found == 1) {
              cout << "Need more data\n";
              return;
            }
            res = arr;
            found = 1;
          }
          arr.pop_back();
        }
        arr.pop_back();
      }
      arr.pop_back();
    }
    arr.pop_back();
  }
  if (!res.size()) {
    cout << "Incorrect data\n";
  } else {
    for (auto el : res) {
      cout << el;
    }
    cout << '\n';
    ;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    play();
  }
  return 0;
}
