#include <bits/stdc++.h>
using namespace std;
struct NODE {
  char w[4];
};
NODE tmp;
vector<NODE> st, stt;
bool use[10];
int bull, cow;
char ss[6];
void back(int index) {
  if (index == 4) {
    int i, j, b, c;
    for (i = 0, b = 0, c = 0; i < 4; ++i)
      for (j = 0; j < 4; ++j)
        if (tmp.w[i] == ss[j]) {
          if (i == j)
            b++;
          else
            c++;
        }
    if (b == bull && c == cow) {
      st.push_back(tmp);
    }
  } else {
    int i;
    for (i = 0; i < 10; ++i) {
      if (use[i]) continue;
      tmp.w[index] = '0' + i;
      use[i] = true;
      back(index + 1);
      use[i] = false;
    }
  }
}
int main() {
  int i, k, j, num, m, n, b, c;
  while (scanf("%d", &num) == 1) {
    st.clear();
    scanf("%s %d %d", ss, &bull, &cow);
    memset(use, 0, sizeof(use));
    back(0);
    for (i = 2; i <= num; ++i) {
      scanf("%s %d %d", ss, &bull, &cow);
      stt.clear();
      for (j = 0, k = st.size(); j < k; ++j) {
        for (m = 0, b = 0, c = 0; m < 4; ++m) {
          for (n = 0; n < 4; ++n) {
            if (st[j].w[m] == ss[n]) {
              if (m == n)
                ++b;
              else
                ++c;
            }
          }
        }
        if (b == bull && c == cow) stt.push_back(st[j]);
      }
      st.clear();
      for (j = 0, k = stt.size(); j < k; ++j) st.push_back(stt[j]);
    }
    if (st.size() > 1)
      puts("Need more data");
    else if (st.size() < 1)
      puts("Incorrect data");
    else {
      for (i = 0; i < 4; ++i) printf("%c", st[0].w[i]);
      putchar('\n');
    }
  }
  return 0;
}
