#include <bits/stdc++.h>
using namespace std;
string a, b;
map<string, int> mapp;
map<string, string> mappp;
string s;
int main() {
  int i, j, k, ans, sum, n, m;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (cin >> n) {
    for (k = 1; k <= n; k++) {
      map<string, int> ma;
      cin >> a;
      for (i = 0; i < a.size(); i++)
        for (j = 1; i + j <= a.size(); j++) {
          s.assign(a, i, j);
          if (!ma[s]) {
            mapp[s]++;
            mappp[s] = a;
            ma[s]++;
          }
        }
    }
    cin >> m;
    for (i = 1; i <= m; i++) {
      cin >> b;
      if (mapp[b])
        cout << mapp[b] << " " << mappp[b] << endl;
      else
        cout << "0 -" << endl;
    }
  }
  return 0;
}
