#include <bits/stdc++.h>
using namespace std;
struct bos {
  int count;
  string str;
};
int main() {
  int n, q;
  cin >> n;
  vector<string> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  string str;
  unordered_map<string, int> m;
  unordered_map<string, string> m2;
  for (int i = 0; i < n; i++) {
    unordered_map<string, bool> tm;
    for (int k = 0; k < a[i].length(); k++) {
      string t = "";
      t = a[i][k];
      if (tm[t] == 0) {
        m[t]++;
        m2[t] = a[i];
        tm[t] = 1;
      }
      for (int j = k + 1; j < a[i].length(); j++) {
        t += a[i][j];
        if (tm[t] == 0) {
          m[t]++;
          m2[t] = a[i];
          tm[t] = 1;
        }
      }
    }
  }
  for (int i = 0; i < q; i++) {
    cin >> str;
    if (m[str] != 0)
      cout << m[str] << " " << m2[str] << endl;
    else
      cout << "0 -" << endl;
  }
  return 0;
}
