#include <bits/stdc++.h>
using namespace std;
struct node {
  int t;
  int x;
};
string a[11000];
unordered_map<string, node> mp;
int main() {
  int n, m;
  string b;
  scanf("%d", &n);
  mp.clear();
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; a[i][j]; j++) {
      b.clear();
      for (int k = j; a[i][k]; k++) {
        b = b + a[i][k];
        if (mp.count(b)) {
          if (mp[b].t != i) {
            mp[b].t = i;
            mp[b].x++;
          }
        } else {
          mp[b].t = i;
          mp[b].x = 1;
        }
      }
    }
  }
  scanf("%d", &m);
  while (m--) {
    cin >> b;
    if (mp.count(b)) {
      printf("%d ", mp[b].x);
      cout << a[mp[b].t] << endl;
    } else
      printf("0 -\n");
  }
  return 0;
}
