#include <bits/stdc++.h>
using namespace std;
struct Trie {
  unordered_map<char, Trie*> mp;
  int c = 0;
  int index = -1;
};
void insert(Trie* head, string& s, int& index) {
  for (int i = 0; i < (int)s.length(); i++) {
    Trie* curr = head;
    for (int j = i; j < (int)s.length(); j++) {
      if (curr->mp.find(s[j]) == curr->mp.end()) {
        curr->mp[s[j]] = new Trie();
      }
      curr = curr->mp[s[j]];
      if (index != curr->index) {
        curr->c++;
        curr->index = index;
      }
    }
  }
}
pair<int, int> get(Trie* head, string& s) {
  Trie* curr = head;
  for (char ch : s) {
    if (curr->mp.find(ch) == curr->mp.end()) {
      return {0, -1};
    }
    curr = curr->mp[ch];
  }
  return {curr->c, curr->index};
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  Trie* head = new Trie();
  vector<string> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    insert(head, v[i], i);
  }
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    auto t = get(head, s);
    int substrings = t.first;
    string matched = (t.second != -1 ? v[t.second] : "-");
    cout << substrings << ' ' << matched << '\n';
  }
  return 0;
}
