#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  map<string, int> m1;
  map<string, string> m2;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    set<string> t;
    for (int i = 0; i < s.size(); ++i) {
      for (int j = i; j < s.size(); ++j) {
        t.insert(s.substr(i, j - i + 1));
      }
    }
    for (auto it = t.begin(); it != t.end(); ++it) {
      ++m1[*it];
      m2[*it] = s;
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> s;
    if (m1.find(s) == m1.end()) {
      cout << "0 -" << '\n';
    } else
      cout << m1[s] << " " << m2[s] << '\n';
  }
}
