#include <bits/stdc++.h>
using namespace std;
map<string, pair<string, int>> sub_word;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  int n;
  cin >> n;
  string s;
  while (n--) {
    cin >> s;
    string c;
    for (int i = 1; i <= s.size(); i++) {
      for (int j = 0; j + i - 1 < s.size(); j++) {
        c = s.substr(j, i);
        if (sub_word.count(c) && sub_word[c].first != s) {
          sub_word[c].second += 1;
          sub_word[c].first = s;
        } else if (!sub_word.count(c))
          sub_word[c] = {s, 1};
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    cin >> s;
    if (sub_word.count(s)) {
      cout << sub_word[s].second << " " << sub_word[s].first << endl;
    } else
      cout << "0 -" << endl;
  }
  return 0;
}
