#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  map<string, int> p1;
  map<string, string> p2;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int len = s.size();
    set<string> st;
    for (int l = 1; l <= len; l++) {
      for (int j = 0; j + l - 1 < len; j++) {
        st.insert(s.substr(j, l));
      }
    }
    for (auto x : st) {
      p1[x]++;
      p2[x] = s;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    string x;
    cin >> x;
    if (p1[x] == 0) p2[x] = "-";
    cout << p1[x] << ' ' << p2[x] << "\n";
  }
}
