#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 1e9;
const int mod = 998244353;
const int maxn = 3e5 + 10;
int n, q;
string s;
map<string, int> f, vis;
map<string, string> d;
void solve(string s) {
  int len = s.size();
  vis.clear();
  for (int i = 0; i < len; i++) {
    string t = "";
    for (int j = i; j < len; j++) {
      t += s[j];
      if (!vis[t]) {
        f[t]++;
        d[t] = s;
        vis[t] = 1;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    solve(s);
  }
  cin >> q;
  while (q--) {
    cin >> s;
    if (f[s])
      cout << f[s] << " " << d[s] << endl;
    else
      cout << f[s] << " "
           << "-" << endl;
  }
  return 0;
}
