#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
bool sortby(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.first >= b.first && a.second >= b.second) return true;
  return false;
}
double area(int x1, int y1, int x2, int y2, int x3, int y3) {
  return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  fast();
  int n, q;
  cin >> n;
  map<string, int> mp1;
  map<string, string> mp2;
  map<pair<string, string>, bool> mp3;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      string x = "";
      for (int h = j; h < s.size(); h++) {
        x += s[h];
        if (!mp3[make_pair(s, x)]) {
          mp1[x]++;
          mp2[x] = s;
          mp3[make_pair(s, x)] = true;
        }
      }
    }
  }
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    if (mp1[s] == 0) {
      cout << mp1[s] << " "
           << "-" << endl;
      continue;
    }
    cout << mp1[s] << " " << mp2[s] << endl;
  }
  return 0;
}
