#include <bits/stdc++.h>
using namespace std;
bool ok(string s, string x) {
  if (s.size() < x.size()) return 0;
  for (int_fast64_t i = 0; i < s.size() - x.size() + 1; i++)
    if (s.substr(i, x.size()) == x) return 1;
  return 0;
}
signed main() {
  int_fast64_t n;
  cin >> n;
  string s;
  map<string, pair<string, int_fast64_t>> m;
  for (int_fast64_t i = 1; i <= n; i++) {
    cin >> s;
    map<string, bool> l;
    for (int_fast64_t j = 0; j < s.size(); j++) {
      for (int_fast64_t k = 1; k <= s.size() - j; k++) {
        string str = s.substr(j, k);
        if (!l[str]) m[str].second++, m[str].first = s, l[str] = 1;
      }
    }
  }
  int_fast64_t q;
  cin >> q;
  for (int_fast64_t i = 1; i <= q; i++) {
    string x;
    cin >> x;
    int_fast64_t cnt = m[x].second;
    if (cnt)
      cout << cnt << ' ' << m[x].first << '\n';
    else
      cout << "0 -\n";
  }
  return 0;
}
