#include <bits/stdc++.h>
using namespace std;
int t[40008];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, k, l, p;
  cin >> n;
  string s;
  map<string, string> ex;
  map<string, int> kol;
  map<string, int> wh;
  for (int u = 1; u <= n; u++) {
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
      string q;
      for (int j = i; j < s.length(); j++) {
        q += s[j];
        if (wh[q] == u) continue;
        if (kol[q] == 0) {
          ex[q] = s;
        }
        wh[q] = u;
        kol[q]++;
      }
    }
  }
  int kk;
  cin >> kk;
  for (int i = 0; i < kk; i++) {
    string s;
    cin >> s;
    int kko = kol[s];
    cout << kko << " ";
    if (kko == 0) {
      cout << "-\n";
    } else {
      cout << ex[s] << '\n';
    }
  }
}
