#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
char rd[10], str[N * 28][10];
int n, m, tot, len, nde, ans, flag;
int cnt[N * 28], mark[N * 28], trie[N * 28][37];
int turn(char ch) {
  if (isdigit(ch))
    return ch - '0';
  else if (ch >= 'a' && ch <= 'z')
    return ch - 'a' + 10;
  else
    return 36;
}
int main() {
  register int i, j, k, h;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s", rd + 1);
    len = strlen(rd + 1);
    for (j = len; j; j--) {
      nde = 0;
      for (k = j; k <= len; k++) {
        int ch = turn(rd[k]);
        if (!trie[nde][ch]) trie[nde][ch] = ++tot;
        nde = trie[nde][ch];
        if (mark[nde] != i) {
          cnt[nde]++, mark[nde] = i;
          memset(str[nde], 0, sizeof str[nde]);
          for (h = 1; h <= len; h++) str[nde][h] = rd[h];
        }
      }
    }
  }
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%s", rd + 1);
    len = strlen(rd + 1), flag = true, nde = 0;
    for (j = 1; j <= len; j++) {
      int ch = turn(rd[j]);
      if (!trie[nde][ch]) {
        flag = 0;
        break;
      }
      nde = trie[nde][ch];
    }
    flag ? printf("%d %s\n", cnt[nde], str[nde] + 1) : printf("0 -\n");
  }
  return 0;
}
