#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q;
  cin >> n;
  vector<string> A(n);
  map<string, set<string> > vals;
  for (long long i = 0; i < n; i++) {
    cin >> A[i];
    for (int j = 0; j < A[i].length(); j++) {
      for (int k = j + 1; k <= A[i].length(); k++) {
        string t = A[i].substr(j, k - j);
        vals[t].insert(A[i]);
      }
    }
  }
  cin >> q;
  for (long long i = 0; i < q; i++) {
    string t;
    cin >> t;
    if (vals.find(t) != vals.end()) {
      cout << vals[t].size() << " " << (*vals[t].begin()) << endl;
    } else
      cout << "0 -" << endl;
  }
  return 0;
}
