#include <bits/stdc++.h>
using namespace std;
map<string, int> qt;
map<string, string> name;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    set<string> ja;
    for (int j = 0; j < s.size(); j++) {
      for (int k = j; k < s.size(); k++) {
        string sub = s.substr(j, k - j + 1);
        if (ja.count(sub)) continue;
        ja.insert(sub);
        qt[sub]++;
        name[sub] = s;
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    cout << qt[s] << " ";
    if (qt[s] == 0)
      cout << '-' << endl;
    else
      cout << name[s] << endl;
  }
  return 0;
}
