#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unordered_map<string, pair<int, string> > total;
  while (n--) {
    string word;
    cin >> word;
    unordered_map<string, int> words;
    for (int i = 0; i < word.length(); i++) {
      for (int len = i; len < word.length(); len++)
        words[word.substr(i, len - i + 1)] = 1;
    }
    for (unordered_map<string, int>::iterator it = words.begin();
         it != words.end(); it++) {
      total[it->first].first += it->second;
      total[it->first].second = word;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    string a;
    ;
    cin >> a;
    if (total.count(a) >= 1)
      cout << total[a].first << " " << total[a].second << endl;
    else
      cout << "0 -" << endl;
  }
  return 0;
}
