#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int N = 100005;
const ll w = 37;
char str[N];
int getval(char c) {
  if (c >= 'a' && c <= 'z') return int(c - 'a');
  if (c >= '0' && c <= '9') return 26 + int(c - '0');
  return 36;
}
map<string, set<int>> cnt;
map<string, string> ans;
int main() {
  int n, sz;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf(" %s", str);
    sz = (int)strlen(str);
    for (int k = 0; k < sz; k++) {
      ll hs = 0;
      string second = "";
      for (int j = k; j < sz; j++) {
        hs = w * hs + getval(str[j]);
        second += str[j];
        cnt[second].insert(i);
        ans[second] = str;
      }
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf(" %s", str);
    sz = (int)strlen(str);
    ll hs = 0;
    for (int j = 0; j < sz; j++) {
      hs = w * hs + getval(str[j]);
    }
    if (!cnt.count(str)) {
      printf("0 -\n");
      continue;
    }
    printf("%d %s\n", (int)cnt[str].size(), ans[str].c_str());
  }
  return 0;
}
