#include <bits/stdc++.h>
using namespace std;
struct Data {
  string num;
  int x, y;
};
int n;
Data t[16];
char s[7], ans[7];
bool vis[16], flag;
void dfs(int d) {
  if (d == 4) {
    bool ok = 1;
    for (int i = 1; i <= n; i++) {
      int cntx = 0, cnty = 0;
      for (int j = 0; j < 4; j++) {
        if (s[j] == t[i].num[j])
          cntx++;
        else if (t[i].num.find(s[j]) != string::npos)
          cnty++;
      }
      if (cntx != t[i].x || cnty != t[i].y) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      if (flag) {
        puts("Need more data");
        exit(0);
      }
      for (int i = 0; i < 4; i++) ans[i] = s[i];
      flag = 1;
    }
    return;
  }
  for (int i = 0; i <= 9; i++)
    if (!vis[i]) {
      s[d] = char(i + '0');
      vis[i] = 1;
      dfs(d + 1);
      vis[i] = 0;
    }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> t[i].num >> t[i].x >> t[i].y;
  dfs(0);
  if (flag) {
    for (int i = 0; i < 4; i++) printf("%c", ans[i]);
    puts("");
  } else
    puts("Incorrect data");
  return 0;
}
