#include <bits/stdc++.h>
using namespace std;
int n, q;
string s;
map<string, int> ans1;
map<string, string> ans2;
void ins() {
  cin >> s;
  set<string> sub;
  int len = s.length();
  for (int i = 0; i < len; i++)
    for (int j = 1; i + j <= len; j++) sub.insert(s.substr(i, j));
  for (auto x : sub) {
    ans1[x]++;
    ans2[x] = s;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) ins();
  scanf("%d", &q);
  while (q--) {
    cin >> s;
    if (ans1[s] == 0)
      printf("0 -\n");
    else
      cout << ans1[s] << ' ' << ans2[s] << endl;
  }
  return 0;
}
