#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 15;
const int MAX_K = 5e5 + 10;
const int INF = 1e9 + 10;
int dp[1 << MAX_N][MAX_N * MAX_N];
int nxt[MAX_K][MAX_N], N, M, K;
map<string, int> Map;
int a[MAX_K];
int ans = INF, id = 0;
void solve(int nid) {
  for (int i = 0; i < MAX_K; i++)
    for (int j = 0; j < MAX_N; j++) nxt[i][j] = K;
  for (int i = 0; i < 1 << MAX_N; i++)
    for (int j = 0; j < MAX_N * MAX_N; j++) dp[i][j] = K;
  for (int c = 0; c < N; c++) {
    int j = 0;
    for (int i = 0; i < K; i++) {
      j = max(j, i + 1);
      while (j < K && a[j] != c) j++;
      nxt[i][c] = j;
    }
  }
  for (int c = 0; c < N; c++) {
    for (int i = 0; i < K; i++)
      if (a[i] == c) {
        dp[1 << c][0] = i;
        break;
      }
  }
  for (int mask = 0; mask < (1 << N); mask++)
    for (int s = 0; s < MAX_N * MAX_N; s++)
      if (dp[mask][s] < K) {
        int sum = 0;
        for (int i = 0; i < N; i++) {
          if (!(mask & (1 << i))) {
            dp[mask | (1 << i)][s + __builtin_popcount(mask) - sum] =
                min(dp[mask | (1 << i)][s + __builtin_popcount(mask) - sum],
                    nxt[dp[mask][s]][i]);
          } else
            sum++;
        }
      }
  for (int s = 0; s < MAX_N * MAX_N; s++)
    if (dp[(1 << N) - 1][s] < K && s < ans) {
      ans = s;
      id = nid;
      break;
    }
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    Map[s] = i;
  }
  cin >> M;
  for (int test = 0; test < M; test++) {
    for (int i = 0; i < MAX_N; i++) a[i] = -1;
    cin >> K;
    int nK = 0;
    for (int i = 0; i < K; i++) {
      string s;
      cin >> s;
      if (Map.find(s) == Map.end()) continue;
      a[nK++] = Map[s];
    }
    K = nK;
    solve(test);
  }
  if (ans == INF) {
    cout << "Brand new problem!\n";
  } else {
    cout << id + 1 << "\n";
    cout << "[:";
    for (int i = 0; i < N * (N - 1) / 2 - ans + 1; i++) cout << "|";
    cout << ":]\n";
  }
  return 0;
}
