#include <bits/stdc++.h>
using namespace std;
map<string, string> a;
map<string, int> b;
string s, g, p;
int main() {
  int n, q;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    int l = s.length();
    for (int j = 0; j < l; j++) {
      for (int k = 1; j + k <= l; k++) {
        string c = s.substr(j, k);
        if (a[c] != s) {
          b[c]++;
          a[c] = s;
        }
      }
    }
  }
  cin >> q;
  for (int h = 0; h < q; h++) {
    cin >> p;
    if (b[p] == 0) {
      cout << b[p] << " "
           << "-" << endl;
    } else {
      cout << b[p] << " " << a[p] << endl;
    }
  }
  return 0;
}
