#include <bits/stdc++.h>
using namespace std;
int arr[1000000];
vector<int> res;
int dp[501][5001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  map<string, pair<int, int>> occurs;
  int n;
  cin >> n;
  vector<string> words(n);
  for (int i = 0; i < n; ++i) {
    cin >> words[i];
    set<string> cur;
    for (int j = 0; j < words[i].size(); ++j) {
      for (int k = 0; k <= words[i].size(); ++k) {
        cur.insert(words[i].substr(j, k));
      }
    }
    cur.erase("");
    for (auto el : cur) {
      auto res = occurs.find(el);
      if (res == occurs.end()) {
        occurs[el] = make_pair(i, 1);
      } else {
        occurs[el] = make_pair(i, res->second.second + 1);
      }
    }
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    string el;
    cin >> el;
    auto res = occurs.find(el);
    if (res == occurs.end()) {
      cout << "0 -\n";
    } else {
      cout << res->second.second << " " << words[res->second.first] << "\n";
    }
  }
}
