#include <bits/stdc++.h>
using namespace std;
map<string, pair<int, string>> m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int len = s.length();
    set<string> toadd;
    for (int x = 0; x < len; x++) {
      for (int y = 1; y + x <= len; y++) {
        string temp = s.substr(x, y);
        if (m.find(temp) == m.end()) {
          m[temp] = {0, s};
        }
        toadd.insert(temp);
      }
    }
    for (auto x : toadd) {
      m[x].first++;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    if (m.find(s) == m.end()) {
      cout << "0 -\n";
    } else
      cout << m[s].first << " " << m[s].second << '\n';
  }
}
