#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct state {
  map<char, int> nex;
  int len, link;
} st[N * 2];
int last, scnt;
set<int>::iterator it;
set<int> exipos[N];
void init() { last = scnt = 1; }
void extend(int c, int id) {
  int p, cur = ++scnt;
  st[cur].len = st[last].len + 1;
  exipos[cur].insert(id);
  for (p = last; p && !st[p].nex[c]; p = st[p].link) st[p].nex[c] = cur;
  if (!p) {
    st[cur].link = 1;
  } else {
    int q = st[p].nex[c];
    if (st[q].len == st[p].len + 1) {
      st[cur].link = q;
    } else {
      int clone = ++scnt;
      st[clone].nex = st[q].nex;
      st[clone].link = st[q].link;
      st[clone].len = st[p].len + 1;
      st[q].link = st[cur].link = clone;
      for (; p && st[p].nex[c] == q; p = st[p].link) st[p].nex[c] = clone;
    }
  }
  last = cur;
}
struct E {
  int to, nex;
} e[N * 4];
int head[N * 2], ecnt;
void adde(int fr, int to) {
  e[++ecnt] = (E){to, head[fr]};
  head[fr] = ecnt;
}
void dfs(int o) {
  for (int j = head[o]; j; j = e[j].nex) {
    dfs(e[j].to);
    for (it = exipos[e[j].to].begin(); it != exipos[e[j].to].end(); it++) {
      exipos[o].insert(*it);
    }
  }
}
int n, m, q, now;
char s[100];
char str[N][10];
int main() {
  scanf("%d", &n);
  init();
  for (int i = 1; i <= n; i++) {
    scanf("%s", str[i] + 1);
    last = 1;
    m = strlen(str[i] + 1);
    for (int j = 1; j <= m; j++) extend(str[i][j] - 'a', i);
  }
  for (int i = 2; i <= scnt; i++) adde(st[i].link, i);
  dfs(1);
  cin >> q;
  while (q--) {
    scanf("%s", s + 1);
    m = strlen(s + 1);
    now = 1;
    for (int i = 1; i <= m; i++) {
      now = st[now].nex[s[i] - 'a'];
    }
    if (!now || !exipos[now].size()) {
      puts("0 -");
    } else {
      int pos = *exipos[now].begin();
      m = strlen(str[pos] + 1);
      printf("%d ", exipos[now].size());
      for (int i = 1; i <= m; i++) putchar(str[pos][i]);
      putchar('\n');
    }
  }
  return 0;
}
