#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  cin >> TESTS;
  map<string, pair<string, long long>> m;
  while (TESTS--) {
    string s;
    cin >> s;
    long long n = s.length();
    for (long long int i = 1; i < n + 1; i++) {
      for (long long int j = 0; j < n + 1 - i; j++) {
        string su = s.substr(j, i);
        if (m[su].first != s) m[su].second++;
        m[su].first = s;
      }
    }
  }
  long long q;
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    string a;
    cin >> a;
    if (m[a].second == 0)
      cout << 0 << " "
           << "-" << '\n';
    else
      cout << m[a].second << " " << m[a].first << '\n';
  }
  return 0;
}
