#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
struct node {
  int id, num;
};
int n, q;
map<string, node> mp;
string s[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  node now;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    int len = s[i].length();
    for (int ii = 0; ii < len; ii++) {
      for (int j = 1; j <= len; j++) {
        if (ii + j - 1 >= len) break;
        string str = s[i].substr(ii, j);
        if (mp.find(str) != mp.end()) {
          if (mp[str].id != i) {
            mp[str].id = i;
            mp[str].num++;
          }
        } else {
          mp[str].id = i;
          mp[str].num++;
        }
      }
    }
  }
  cin >> q;
  while (q--) {
    string str;
    cin >> str;
    if (mp.find(str) != mp.end()) {
      now = mp[str];
      cout << now.num << ' ' << s[now.id] << endl;
    } else
      cout << "0 -\n";
  }
}
