#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  int a, b, c;
} f[111];
int n;
int main() {
  while (cin >> n) {
    for (int i = 0; i < n; ++i) {
      cin >> f[i].a >> f[i].b >> f[i].c;
    }
    int ans = 0, kkans;
    int a, b, c, d, z, bb, cc, zz;
    for (int i = 0; i < 10000; ++i) {
      z = i;
      a = z % 10;
      z /= 10;
      b = z % 10;
      z /= 10;
      c = z % 10;
      z /= 10;
      d = z % 10;
      if (a == b || a == c || a == d || b == c || b == d || c == d) continue;
      bool yes = 1;
      for (int j = 0; j < n; ++j) {
        bb = 0;
        cc = 0;
        z = f[j].a;
        zz = z % 10;
        if (a == zz) bb++;
        if (b == zz) cc++;
        if (c == zz) cc++;
        if (d == zz) cc++;
        z /= 10;
        zz = z % 10;
        if (b == zz) bb++;
        if (a == zz) cc++;
        if (c == zz) cc++;
        if (d == zz) cc++;
        z /= 10;
        zz = z % 10;
        if (c == zz) bb++;
        if (a == zz) cc++;
        if (b == zz) cc++;
        if (d == zz) cc++;
        z /= 10;
        zz = z % 10;
        if (d == zz) bb++;
        if (a == zz) cc++;
        if (b == zz) cc++;
        if (c == zz) cc++;
        if (bb != f[j].b || cc != f[j].c) {
          yes = 0;
          break;
        }
      }
      if (yes) {
        ans++;
        kkans = i;
      }
    }
    if (ans == 0)
      cout << "Incorrect data\n";
    else if (ans == 1)
      printf("%04d\n", kkans);
    else
      cout << "Need more data\n";
  }
}
