#include <bits/stdc++.h>
using namespace std;
struct State {
  int X[4];
  State &operator=(const State &ret) {
    for (int i = 0; i < 4; i++) X[i] = ret.X[i];
    return *this;
  }
};
struct Node {
  int x, y;
  State cc;
} node[120];
int get_x(State a, State b) {
  int cnt = 0;
  for (int i = 0; i < 4; i++) {
    if (a.X[i] == b.X[i]) cnt++;
  }
  return cnt;
}
int get_y(State a, State b) {
  int cnt = 0;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++) {
      if (a.X[i] == b.X[j] && i != j) {
        cnt++;
        break;
      }
    }
  return cnt;
}
int ff[13];
bool check(int a, int b, int c, int d) {
  memset(ff, 0, sizeof(ff));
  ff[a]++;
  ff[b]++;
  ff[c]++;
  ff[d]++;
  int cnt = 0;
  for (int i = 0; i <= 9; i++) {
    if (ff[i] == 1) cnt++;
  }
  if (cnt == 4) return true;
  return false;
}
int main() {
  int n, sum;
  while (scanf("%d", &n) == 1) {
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d", &sum, &node[i].x, &node[i].y);
      for (int j = 3; j >= 0; j--) {
        node[i].cc.X[j] = sum % 10;
        sum = sum / 10;
      }
    }
    int cnt = 0;
    State re;
    for (int i = 0; i <= 9; i++)
      for (int j = 0; j <= 9; j++)
        for (int k = 0; k <= 9; k++)
          for (int y = 0; y <= 9; y++) {
            if (check(i, j, k, y)) {
              State tmp;
              tmp.X[0] = i;
              tmp.X[1] = j;
              tmp.X[2] = k;
              tmp.X[3] = y;
              bool flag = true;
              for (int s = 0; s < n; s++) {
                int nx = get_x(node[s].cc, tmp);
                int ny = get_y(node[s].cc, tmp);
                if (!(nx == node[s].x && ny == node[s].y)) flag = false;
              }
              if (flag) {
                cnt++;
                re = tmp;
              }
            }
          }
    if (!cnt)
      printf("Incorrect data\n");
    else if (cnt == 1) {
      for (int i = 0; i < 4; i++) printf("%d", re.X[i]);
      printf("\n");
    } else
      printf("Need more data\n");
  }
  return 0;
}
