#include <bits/stdc++.h>
using namespace std;
string file[10005];
unordered_map<string, pair<int, int> > ss;
unordered_map<string, bool> sk;
void deal(const string &in, int loc) {
  sk.clear();
  int len = in.size();
  string temp;
  for (int i = 1; i <= len; ++i) {
    for (int j = 0; j <= len - i; ++j) {
      temp.clear();
      for (int k = j; k < i + j; ++k) {
        temp.push_back(in[k]);
      }
      auto &flag = sk[temp];
      if (flag)
        continue;
      else {
        flag = true;
        auto it = ss.find(temp);
        if (it == ss.end()) {
          ss.emplace(make_pair(temp, make_pair(loc, 1)));
        } else
          ++it->second.second;
      }
    }
  }
}
string quest;
int main() {
  int n, m;
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> file[i];
    deal(file[i], i);
  }
  cin >> m;
  while (m--) {
    cin >> quest;
    auto it = ss.find(quest);
    if (it != ss.end()) {
      cout << it->second.second << " " << file[it->second.first] << "\n";
    } else {
      cout << "0 -\n";
    }
  }
  return 0;
}
