#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  map<string, pair<int, string> > hash;
  while (n--) {
    string a;
    cin >> a;
    int l = a.length();
    for (int i = 1; i <= l; i++) {
      for (int j = 0; j <= l - i; j++) {
        string b = a.substr(j, i);
        if (hash[b].second == a) continue;
        hash[b].first++;
        hash[b].second = a;
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    string a;
    cin >> a;
    if (hash[a].first) {
      cout << hash[a].first << " " << hash[a].second << "\n";
    } else
      cout << "0 -\n";
  }
  return 0;
}
