#include <bits/stdc++.h>
using namespace std;
struct node {
  int num;
  string ss;
};
unordered_map<string, node> mm;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n) {
    mm.clear();
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      for (int j = 0; j < s.length(); j++) {
        for (int k = 1; k <= (s.length() - j); k++) {
          string sb = s.substr(j, k);
          if (mm.find(sb) != mm.end() && mm[sb].ss != s) {
            mm[sb].num++;
            mm[sb].ss = s;
          } else if (mm.find(sb) == mm.end()) {
            node temp;
            temp.num = 1;
            temp.ss = s;
            mm[sb] = temp;
          }
        }
      }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      string s;
      cin >> s;
      if (mm.find(s) != mm.end()) {
        cout << mm[s].num << " " << mm[s].ss << endl;
      } else {
        cout << 0 << " -" << endl;
      }
    }
  }
  return 0;
}
