#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans = ans * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return ans;
}
const int N = 2e5 + 11;
int n;
string a[10005];
map<string, int> ans;
map<string, string> Ans;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int len = a[i].size();
    map<string, int> vis;
    for (int j = 0; j < len; j++) {
      for (int k = j; k < len; k++) {
        if (vis[a[i].substr(j, k - j + 1)]) continue;
        vis[a[i].substr(j, k - j + 1)] = 1;
        ans[a[i].substr(j, k - j + 1)]++;
        Ans[a[i].substr(j, k - j + 1)] = a[i];
      }
    }
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    string a;
    cin >> a;
    if (ans[a] == 0) {
      cout << "0 -\n";
      continue;
    }
    cout << ans[a] << ' ' << Ans[a] << endl;
  }
  return 0;
}
