#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> vec(n);
  map<string, vector<int> > mp;
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    set<string> st;
    for (int l = 0; l < vec[i].size(); l++) {
      for (int r = l + 1; r <= vec[i].size(); r++) {
        string sb = vec[i].substr(l, r - l);
        st.insert(sb);
      }
    }
    for (set<string>::iterator p = st.begin(); p != st.end(); p++) {
      if (mp.count(*p) == 0) {
        mp[*p] = vector<int>();
      }
      mp[*p].push_back(i);
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string s;
    cin >> s;
    if (mp.count(s) == 0) {
      cout << 0 << " -" << endl;
    } else {
      cout << mp[s].size() << " " << vec[mp[s][0]] << endl;
    }
  }
}
