#include <bits/stdc++.h>
using namespace std;
string str[10005];
int n, q, top;
map<string, int> s;
int tot[500005];
int begi[500005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int k = 0; k < n; k++) {
    cin >> str[k];
    set<string> temps;
    for (int i = 1; i <= str[k].length(); i++) {
      for (int j = 0; i + j <= str[k].length(); j++) {
        temps.insert(str[k].substr(j, i));
      }
    }
    for (auto temp : temps) {
      if (s.find(temp) != s.end()) {
        tot[s[temp]]++;
      } else {
        s[temp] = ++top;
        begi[top] = k;
        tot[top] = 1;
      }
    }
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    string temps;
    cin >> temps;
    if (s.find(temps) == s.end()) {
      cout << 0 << ' ' << '-' << endl;
    } else {
      cout << tot[s[temps]] << ' ' << str[begi[s[temps]]] << endl;
    }
  }
  return 0;
}
