#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
set<string> st;
map<string, string> nt;
int main() {
  ios_base::sync_with_stdio(false);
  string a, ans;
  int n, q;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    st.clear();
    for (int i = 0; i < a.size(); i++) {
      ans = "";
      for (int j = i; j < a.size(); j++) {
        ans += a[j];
        nt[ans] = a;
        st.insert(ans);
      }
    }
    for (set<string>::iterator it = st.begin(); it != st.end(); it++) mp[*it]++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> a;
    int pans = 0;
    pans = mp[a];
    cout << pans << " ";
    if (pans == 0)
      cout << "-\n";
    else
      cout << nt[a] << "\n";
  }
  return 0;
}
