#include <bits/stdc++.h>
using namespace std;
struct answer {
  int b, c;
  bool operator==(answer other) const { return b == other.b && c == other.c; }
  bool operator!=(answer other) const { return !(*this == other); }
};
answer eval(string secret, string query) {
  string left_s, left_q;
  answer ans = {0, 0};
  for (int i = 0; i < (int)(4); i++) {
    if (secret[i] == query[i])
      ans.b++;
    else {
      left_s.push_back(secret[i]);
      left_q.push_back(query[i]);
    }
  }
  while (!left_s.empty()) {
    auto it = find(left_q.begin(), left_q.end(), left_s.back());
    if (it != left_q.end()) {
      left_q.erase(it);
      ans.c++;
    }
    left_s.pop_back();
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<string> q(n);
  vector<answer> anss(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> q[i] >> anss[i].b >> anss[i].c;
  }
  vector<string> answers;
  for (int a = 0; a < 10; a++) {
    for (int b = 0; b < 10; b++) {
      if (a == b) continue;
      for (int c = 0; c < 10; c++) {
        if (a == c || b == c) continue;
        for (int d = 0; d < 10; d++) {
          if (a == d || b == d || c == d) continue;
          string s;
          s.push_back('0' + a);
          s.push_back('0' + b);
          s.push_back('0' + c);
          s.push_back('0' + d);
          bool ok = true;
          for (int i = 0; i < (int)(n); i++) {
            if (anss[i] != eval(s, q[i])) {
              ok = false;
            }
          }
          if (ok) {
            answers.push_back(s);
          }
        }
      }
    }
  }
  if (answers.empty()) {
    cout << "Incorrect data" << endl;
  } else if (answers.size() > 1) {
    cout << "Need more data" << endl;
  } else {
    cout << answers[0] << endl;
  }
  return 0;
}
