#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int N = 2e5 + 5;
const int INF = N;
int ans[N];
void solve() {
  int n;
  cin >> n;
  map<string, int> m;
  map<string, string> make_pair;
  for (int i = (0); i < (n); ++i) {
    string second;
    cin >> second;
    set<string> se;
    for (int j = (0); j < ((int)(second).size()); ++j) {
      for (int k = (j); k < ((int)(second).size()); ++k) {
        string t = second.substr(j, k - j + 1);
        if (!se.count(t)) {
          m[t]++;
          make_pair[t] = second;
          se.insert(t);
        }
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    string ss;
    cin >> ss;
    cout << m[ss] << " ";
    if (m[ss] == 0)
      cout << "-\n";
    else
      cout << make_pair[ss] << '\n';
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
}
