#include <bits/stdc++.h>
using namespace std;
map<string, set<int> > mp;
int main(int argc, char *argv[]) {
  int n;
  string s[10005];
  cin >> n;
  string temp;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    int len = s[i].length();
    for (int j = 1; j <= len; j++) {
      for (int h = 0; h + j <= len; h++) {
        temp = s[i].substr(h, j);
        mp[temp].insert(i);
      }
    }
  }
  int k;
  cin >> k;
  while (k--) {
    string ss;
    cin >> ss;
    if (!mp.count(ss)) {
      cout << "0 -" << endl;
    } else {
      cout << mp[ss].size() << " " << s[*mp[ss].begin()] << endl;
    }
  }
  return 0;
}
