#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string Num, A[10];
  int B[10], C[10];
  for (int i = 0; i < n; i++) cin >> A[i] >> B[i] >> C[i];
  int correctN = 0;
  for (int a = 0; a < 10; a++) {
    for (int b = 0; b < 10; b++) {
      if (a != b)
        for (int c = 0; c < 10; c++) {
          if (c != a && c != b)
            for (int d = 0; d < 10; d++) {
              if (d != a && d != b && d != c) {
                string s = "";
                s += ('0' + a);
                s += ('0' + b);
                s += ('0' + c);
                s += ('0' + d);
                int cond = 0;
                for (int i = 0; i < n; i++) {
                  int bb = 0, cc = 0;
                  for (int j = 0; j < 4; j++) {
                    for (int k = 0; k < 4; k++) {
                      if (s[j] == A[i][k]) {
                        if (j != k)
                          cc++;
                        else
                          bb++;
                      }
                    }
                  }
                  if (bb == B[i] && cc == C[i]) cond++;
                }
                if (cond == n) {
                  Num = s;
                  correctN++;
                }
              }
            }
        }
    }
  }
  if (correctN == 0)
    cout << "Incorrect data";
  else if (correctN == 1)
    cout << Num;
  else if (correctN > 1)
    cout << "Need more data";
  return 0;
}
