#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long N;
  cin >> N;
  ;
  map<string, pair<long long, string>> Q;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    ;
    set<string> Z;
    for (int j = 0; j < S.length(); j++) {
      for (int k = 1; k < (long long)(S.length()) - j + 1; k++) {
        Z.insert(S.substr(j, k));
      }
    }
    for (auto s : Z) {
      Q[s].first++;
      Q[s].second = S;
    }
  }
  long long QN;
  cin >> QN;
  ;
  for (int i = 0; i < QN; i++) {
    string S;
    cin >> S;
    ;
    if (Q[S].first == 0) {
      cout << "0 -" << endl;
    } else {
      cout << Q[S].first << " " << Q[S].second << endl;
    }
  }
  return 0;
}
