#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
const long double EPS = 1e-9;
const int MOD = 1000000007;
const long long LLINF = 1000000000000000001;
const int maxn = 10042;
int n;
string s[maxn];
map<string, int> mcount;
map<string, int> mexample;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    set<string> mysubs;
    for (int j = 0; j <= ((int)(s[i]).size()) - 1; j++)
      for (int k = 1; k <= ((int)(s[i]).size()) - j; k++) {
        string t = s[i].substr(j, k);
        if (mysubs.find(t) == mysubs.end()) {
          mysubs.insert(t);
          mcount[s[i].substr(j, k)]++;
          mexample[s[i].substr(j, k)] = i;
        }
      }
  }
  int q;
  cin >> q;
  for (int cc = 1; cc <= q; cc++) {
    string m;
    cin >> m;
    int a1 = mcount[m];
    if (a1 == 0)
      cout << "0 -\n";
    else
      cout << a1 << ' ' << s[mexample[m]] << '\n';
  }
}
