#include <bits/stdc++.h>
using namespace std;
map<string, pair<int, int> > mp;
string a[10005], str;
int main(void) {
  int i, j, k, n, m, len;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    len = a[i].size();
    a[i] = ' ' + a[i];
    for (j = 1; j <= len; ++j) {
      string tmp;
      for (k = j; k <= len; ++k) {
        tmp += a[i][k];
        pair<int, int>& pos = mp[tmp];
        if (pos.second != i) ++pos.first, pos.second = i;
      }
    }
  }
  cin >> m;
  for (i = 1; i <= m; ++i) {
    cin >> str;
    if (mp.count(str))
      cout << mp[str].first << a[mp[str].second] << "\n";
    else
      cout << "0 -\n";
  }
  return 0;
}
