#include <bits/stdc++.h>
using namespace std;
map<string, int> m1;
map<string, string> m2;
map<string, string>::iterator it;
int main() {
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    int l = s.size();
    for (int i = 0; i < l; i++) {
      for (int j = 1; j <= l - i; j++) {
        string str2(s.substr(i, j));
        if (m2[str2] != s) m1[str2]++;
        m2[str2] = s;
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    if (m2[s] == "") m2[s] = "-";
    cout << m1[s] << ' ' << m2[s] << endl;
  }
  return 0;
}
