#include <bits/stdc++.h>
using namespace std;
int n, q;
string s;
char tmp[10];
map<string, int> cnt;
map<string, string> ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    set<string> sset;
    scanf("%s", tmp);
    s = (string)tmp;
    for (int j = 0; j < s.length(); j++) {
      for (int k = j; k < s.length(); k++) {
        string t = s.substr(j, k - j + 1);
        if (sset.find(t) == sset.end()) {
          ans[t] = s;
          cnt[t]++;
          sset.insert(t);
        }
      }
    }
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%s", tmp);
    s = (string)tmp;
    if (cnt[s] == 0) {
      printf("0 -\n");
    } else {
      printf("%d %s\n", cnt[s], ans[s].c_str());
    }
  }
}
