#include <bits/stdc++.h>
using namespace std;
const int N = 3e2 + 10, N2 = 1e5 + 10;
int freq[15], cor, intcor, n, t, suc, prob;
pair<pair<int, int>, int> arr[20];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &arr[i].first.first, &arr[i].first.second, &arr[i].second);
  }
  for (int i = 100; i < 10000; i++) {
    int val = i;
    bool flg = true;
    for (int j = 0; j < 4; j++) {
      freq[val % 10]++;
      if (freq[val % 10] > 1) {
        flg = false;
      }
      val /= 10;
    }
    memset(freq, 0, sizeof freq);
    if (!flg) continue;
    bool flg2 = true;
    for (int ii = 0; ii < n; ii++) {
      val = i;
      int num = arr[ii].first.first, inplace = 0, dif = 0,
          tnum = arr[ii].first.first, a1[7], a2[7];
      for (int i = 0; i < 4; i++) {
        if (tnum % 10 == val % 10) inplace++;
        a1[i] = tnum % 10;
        a2[i] = val % 10;
        tnum /= 10;
        val /= 10;
      }
      for (int i = 0; i < 4; i++)
        for (int j = 0; j < 4; j++) {
          if (j != i)
            if (a1[j] == a2[i]) dif++;
        }
      if (inplace != arr[ii].first.second || dif != arr[ii].second) {
        flg2 = false;
      }
    }
    if (flg2) {
      intcor = i;
      cor++;
    }
  }
  if (cor == 0) {
    return printf("Incorrect data\n"), 0;
  }
  if (cor == 1) {
    if (intcor < 1000) cout << "0";
    return printf("%d\n", intcor), 0;
  }
  return printf("Need more data\n"), 0;
}
