#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  string a;
  cin >> n;
  map<string, int> m;
  map<string, string> ma;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    int len = a.length();
    for (int i = 0; i <= len; i++) {
      for (int j = 0; j + i <= len; j++) {
        string s1 = a.substr(i, j);
        if (ma[s1] != a) {
          m[s1]++;
          ma[s1] = a;
        }
      }
    }
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> a;
    if (m[a] != 0) {
      cout << m[a] << " " << ma[a] << endl;
    } else
      printf("0 -\n");
  }
  return 0;
}
