#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10, M = 7e5 + 10;
int sz = 0, num[M], bel[M];
char s[N][10];
set<unsigned long long> S;
map<unsigned long long, int> ms;
inline int idx(const char &ch) {
  if (ch <= 'z' && ch >= 'a') return ch - 'a' + 1;
  if (ch <= '9' && ch >= '0') return ch - '0' + 27;
  return 37;
}
inline void get(char *s, int id) {
  int len = strlen(s);
  for (int i = 0; i < len; i++)
    for (int j = i; j < len; j++) {
      unsigned long long t = 0;
      for (int k = i; k <= j; k++) t = t * 41 + idx(s[k]);
      S.insert(t);
    }
  for (unsigned long long t : S) {
    int &tmp = ms[t];
    if (!tmp) tmp = ++sz;
    num[tmp]++, bel[tmp] = id;
  }
  S.clear();
}
void work() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    get(s[i], i);
  }
  int q;
  scanf("%d", &q);
  char ss[10];
  while (q--) {
    scanf("%s", ss);
    int len = strlen(ss);
    unsigned long long t = 0;
    for (int i = 0; i < len; i++) t = t * 41 + idx(ss[i]);
    if (!ms.count(t))
      puts("0 -");
    else {
      int tmp = ms[t];
      printf("%d %s\n", num[tmp], s[bel[tmp]]);
    }
  }
}
int main() {
  work();
  return 0;
}
