#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> cnt;
  map<string, string> st;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    map<string, int> last;
    string s;
    cin >> s;
    int sz = s.size();
    for (int j = 0; j < sz; j++) {
      string a;
      for (int k = 1; k <= sz; k++) {
        a = s.substr(j, k);
        if (last[a] == 0) {
          last[a] = 1;
          cnt[a]++;
          st[a] = s;
        }
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    cout << cnt[s] << " ";
    if (cnt[s] == 0)
      cout << "-" << endl;
    else
      cout << st[s] << endl;
  }
  return 0;
}
