#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, pair<int, string>> m;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    set<string> done;
    for (int j = 0; j < str.length(); j++) {
      string t = "";
      for (int k = j; k < str.length(); ++k) {
        t += str[k];
        if (done.count(t)) continue;
        done.insert(t);
        auto it = m.find(t);
        if (it != m.end()) {
          it->second.first += 1;
        } else {
          m[t] = {1, str};
        }
      }
    }
  }
  int q;
  cin >> q;
  for (int qi = 0; qi < q; ++qi) {
    string s;
    cin >> s;
    auto it = m.find(s);
    if (it != m.end()) {
      cout << it->second.first << " " << it->second.second << "\n";
    } else {
      cout << "0 -"
           << "\n";
    }
  }
}
