#include <bits/stdc++.h>
using namespace std;
int n, T, m, a[500010], f[1 << 16][125], nxt[500010][16], pos[16];
char s[16];
map<string, int> mp;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s), mp[s] = i;
  }
  int res = -1, ans = (n * (n - 1) >> 1) + 1;
  scanf("%d", &T);
  for (int id = 1; id <= T; id++) {
    scanf("%d", &m), memset(pos, 0x3f, sizeof(pos));
    for (int i = 1; i <= m; i++) {
      scanf("%s", s), a[i] = mp.count(s) ? mp[s] : -1;
    }
    for (int i = m; ~i; i--) {
      for (int j = 0; j < n; j++) nxt[i][j] = pos[j];
      if (a[i] != -1) pos[a[i]] = i;
    }
    memset(f, 0x3f, sizeof(f)), f[0][0] = 0;
    for (int i = 0; i < (1 << n); i++) {
      for (int j = 0; j <= (n * (n - 1) >> 1); j++) {
        for (int k = 0; k < n; k++) {
          if (!(i & (1 << k)) && f[i][j] <= m) {
            int &x = f[i ^ (1 << k)][j + __builtin_popcount(i >> k)];
            x = min(x, nxt[f[i][j]][k]);
          }
        }
      }
    }
    for (int i = ans - 1; ~i; i--) {
      if (f[(1 << n) - 1][i] <= m) res = id, ans = i;
    }
  }
  if (res == -1) {
    printf("Brand new problem!");
  } else {
    printf("%d\n[:%s:]", res,
           string((n * (n - 1) >> 1) + 1 - ans, '|').c_str());
  }
  return 0;
}
