#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, q;
string s[N];
map<string, pair<int, string>> M;
vector<string> a;
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    a.clear();
    for (int j = 0; j < s[i].size(); ++j)
      for (int L = 0; L + j < s[i].size(); ++L)
        a.push_back(s[i].substr(j, L + 1));
    sort(a.begin(), a.end());
    int m = unique(a.begin(), a.end()) - a.begin();
    for (int j = 0; j < m; ++j) M[a[j]].first++, M[a[j]].second = s[i];
  }
  cin >> q;
  while (q--) {
    string t;
    cin >> t;
    cout << M[t].first << " " << (M[t].first ? M[t].second : "-") << endl;
  }
  return 0;
}
