#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  map<string, set<int>> hsh;
  cin >> n;
  vector<string> files(n);
  for (int i = 0; i < n; i++) {
    cin >> files[i];
    for (int l = 1; l <= files[i].length(); l++) {
      for (int j = 0; j <= files[i].length() - l; j++)
        hsh[files[i].substr(j, l)].insert(i);
    }
  }
  cin >> q;
  string s;
  while (q--) {
    cin >> s;
    if (hsh.find(s) == hsh.end())
      cout << "0 -\n";
    else
      cout << hsh[s].size() << " " << files[*(hsh[s].begin())] << endl;
  }
}
