#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
map<string, long long> m;
map<string, string> m1;
void su(string s, long long n) {
  set<string> se;
  for (long long i = 0; i < n; i++)
    for (long long len = 1; len <= n - i; len++) {
      if (m1.find(s.substr(i, len)) == m1.end()) {
        m1[s.substr(i, len)] = s;
      }
      se.insert(s.substr(i, len));
    }
  for (auto i = se.begin(); i != se.end(); i++) {
    m[*i]++;
  }
}
int main() {
  long long i, j;
  ;
  long long n;
  cin >> n;
  string s;
  for (i = 0; i < n; i++) {
    cin >> s;
    su(s, s.length());
  }
  long long q;
  cin >> q;
  while (q--) {
    cin >> s;
    if (m1.find(s) != m1.end())
      cout << m[s] << " " << m1[s] << endl;
    else {
      cout << 0 << " "
           << "-" << endl;
    }
  }
}
