#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
void input() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void Sieve(long long n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
long long pw(int x, unsigned int y, int p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = 1ll * (res * x) % p;
    y = y >> 1;
    x = (1ll * x * x) % p;
  }
  return res;
}
int n, q;
map<string, pair<int, string>> dict;
int main() {
  input();
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int l = s.length();
    vector<string> v;
    for (int i = 0; i < l; i++) {
      string curr = "";
      for (int j = i; j < l; j++) {
        curr += s[j];
        v.push_back(curr);
      }
    }
    sort((v).begin(), (v).end());
    v.resize(unique((v).begin(), (v).end()) - v.begin());
    for (auto c : v) {
      dict[c].first++;
      dict[c].second = s;
    }
  }
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    if (dict.find(s) != dict.end()) {
      cout << dict[s].first << " " << dict[s].second << "\n";
    } else
      cout << "0 -\n";
  }
  return 0;
}
