#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  map<string, pair<int, string>> mp;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    set<string> st;
    for (int l = 0; l < s.length(); ++l) {
      for (int r = l; r < s.length(); ++r) {
        st.insert(string(s.data() + l, s.data() + r + 1));
      }
    }
    for (auto it : st) {
      mp[it].first++, mp[it].second = s;
    }
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    string s;
    cin >> s;
    if (mp[s].first == 0) {
      cout << 0 << " -\n";
      continue;
    }
    cout << mp[s].first << ' ' << mp[s].second << '\n';
  }
}
