#include <bits/stdc++.h>
using namespace std;
string st;
set<string> S;
map<string, int> mp;
map<string, string> mp2;
int n, q;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    S.clear();
    cin >> st;
    int len = st.length();
    for (int fr = 0; fr < len; fr++)
      for (int ed = fr; ed < len; ed++) {
        string sb = st.substr(fr, ed - fr + 1);
        if (S.count(sb)) {
        } else {
          S.insert(sb);
          mp[sb]++;
          mp2[sb] = st;
        }
      }
  }
  cin >> q;
  while (q--) {
    cin >> st;
    string attr2 = "-";
    if (mp2.count(st)) attr2 = mp2[st];
    int attr1 = 0;
    if (mp.count(st)) attr1 = mp[st];
    cout << attr1 << " " << attr2 << "\n";
  }
  return 0;
}
