#include <bits/stdc++.h>
using namespace std;
int findInd(char c) {
  if (c >= 'a' && c <= 'z') return c - 'a';
  if (c >= '0' && c <= '9') return c - '0' + 26;
  return 36;
}
struct Node {
  char c;
  set<int> cnt;
  Node *nxt[40];
  Node(char cc) {
    c = cc;
    for (int i = 0; i < 40; i++) nxt[i] = NULL;
  }
} * root[40];
Node *findLeaf(string str, bool isUpdate, int listInd) {
  int i, ind;
  Node *cur = NULL;
  for (i = 0; i < str.size(); i++) {
    ind = findInd(str[i]);
    if (i == 0) {
      if (root[ind] == NULL) {
        if (isUpdate == false) return NULL;
        root[ind] = new Node(str[i]);
      }
      cur = root[ind];
    } else {
      if (cur->nxt[ind] == NULL) {
        if (isUpdate == false) return NULL;
        cur->nxt[ind] = new Node(str[i]);
      }
      cur = cur->nxt[ind];
    }
    if (isUpdate) {
      cur->cnt.insert(listInd);
    }
  }
  return cur;
}
void updateString(string wrd, int listInd) {
  Node *cur;
  for (int i = 0; i < wrd.size(); i++) {
    cur = findLeaf(wrd.substr(i), true, listInd);
  }
}
int main() {
  int n, i, q;
  Node *cur;
  string s, allStr[10010];
  set<int>::iterator it;
  for (i = 0; i < 40; i++) {
    root[i] = NULL;
  }
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s;
    allStr[i] = s;
    updateString(s, i);
  }
  cin >> q;
  while (q--) {
    cin >> s;
    cur = findLeaf(s, false, -1);
    if (cur == NULL) {
      cout << 0 << " -" << endl;
    } else {
      it = cur->cnt.begin();
      cout << cur->cnt.size() << " " << allStr[(*it)] << endl;
    }
  }
  return 0;
}
