#include <bits/stdc++.h>
using namespace std;
struct two {
  long long int f, s;
};
signed main() {
  long long int n;
  cin >> n;
  map<string, set<string> > mp;
  while (n--) {
    string str;
    cin >> str;
    for (long long int i = 0; i < str.size(); i++) {
      string tmp = "";
      for (long long int j = i; j < str.size(); j++) {
        tmp += str[j];
        mp[tmp].insert(str);
      }
    }
  }
  long long int q;
  cin >> q;
  while (q--) {
    string str;
    cin >> str;
    if (mp.find(str) != mp.end())
      cout << mp[str].size() << " " << *mp[str].begin() << endl;
    else
      cout << 0 << " " << '-' << endl;
  }
}
