#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
typedef struct NODE {
  bool leaf;
  vector<int> idx;
  int last;
  NODE *fail;
  NODE *next[37];
} NODE;
int ans[50005];
string anss[50005];
NODE node[400005];
string str[10005];
int alloc = 0, alloc2 = 1;
int cnt;
void add(NODE *root, char *ch) {
  if (!(*ch)) {
    root->leaf = true;
    root->last = -1;
    root->idx.push_back(cnt);
  } else {
    int son;
    if (*ch == '.')
      son = 36;
    else if (*ch >= 'a')
      son = *ch - 'a' + 10;
    else
      son = *ch - '0';
    if (root->next[son] == NULL) root->next[son] = node + (alloc++);
    add(root->next[son], ch + 1);
  }
}
void build(NODE *root) {
  queue<NODE *> que;
  NODE *p, *f;
  root->fail = NULL;
  que.push(root);
  while (!que.empty()) {
    p = que.front();
    que.pop();
    for (int i = 0; i < 37; i++) {
      if (p->next[i]) {
        que.push(p->next[i]);
        f = p->fail;
        while (f && f->next[i] == NULL) f = f->fail;
        if (f == NULL)
          p->next[i]->fail = root;
        else
          p->next[i]->fail = f->next[i];
      }
    }
  }
}
void match(NODE *root, string s, int id) {
  NODE *p = root;
  for (int i = 0; i < (int)s.length(); i++) {
    NODE *f;
    int son;
    if (s[i] == '.')
      son = 36;
    else if (s[i] >= 'a')
      son = s[i] - 'a' + 10;
    else
      son = s[i] - '0';
    while (p && !p->next[son]) p = p->fail;
    if (!p)
      p = root;
    else
      p = p->next[son];
    f = p;
    while (f != root) {
      if (f->leaf) {
        for (int i = 0; i < f->idx.size(); i++) {
          anss[f->idx[i]] = s;
          if (f->last < id) ans[f->idx[i]]++;
        }
        f->last = id;
      }
      f = f->fail;
    }
  }
}
int main() {
  NODE root = {0};
  int n, q;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> str[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    char s[9];
    scanf("%s", s);
    cnt = i;
    add(&root, s);
  }
  build(&root);
  for (int i = 0; i < n; i++) match(&root, str[i], i);
  for (int i = 0; i < q; i++) {
    printf("%d ", ans[i]);
    if (ans[i] == 0)
      printf("-\n");
    else
      cout << anss[i] << endl;
  }
  return 0;
}
