#include <bits/stdc++.h>
using namespace std;
int N, Q;
map<string, int> mp, vis;
map<string, string> st;
int main() {
  register int i, j, k;
  string s;
  cin >> N;
  for (i = 1; i <= N; ++i) {
    cin >> s;
    vis.clear();
    for (j = 0; j < s.size(); ++j)
      for (k = 1; k <= s.size() - j; ++k)
        if (!vis[s.substr(j, k)])
          vis[s.substr(j, k)] = 1, ++mp[s.substr(j, k)], st[s.substr(j, k)] = s;
  }
  cin >> Q;
  while (Q--) {
    cin >> s;
    cout << mp[s] << ' ' << (mp[s] == 0 ? "-" : st[s]) << endl;
  }
  return 0;
}
