#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, pair<string, int>> mymap;
  set<string> s;
  int n, q;
  string cur_str;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> cur_str;
    s.clear();
    int len = cur_str.length();
    for (int j = 0; j < len; ++j) {
      for (int k = 1; k <= len - j; ++k) {
        string key = cur_str.substr(j, k);
        if (s.count(key) != 0)
          continue;
        else
          s.insert(key);
        if (mymap.find(key) == mymap.end()) {
          mymap[key] = make_pair(cur_str, 1);
        } else {
          mymap[key].second++;
        }
      }
    }
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> cur_str;
    if (mymap.find(cur_str) == mymap.end())
      cout << "0 -" << endl;
    else
      cout << "" << mymap[cur_str].second << " " << mymap[cur_str].first
           << endl;
  }
}
