#include <bits/stdc++.h>
using namespace std;
map<string, string> s;
map<string, int> mp;
int main() {
  int n, m, i, j;
  string a;
  cin >> n;
  while (n--) {
    cin >> a;
    int a1 = a.size();
    map<string, int> mp1;
    for (i = 0; i <= a1 - 1; i++)
      for (j = 1; j <= a1; j++) {
        string k = a.substr(i, j);
        if (mp1[k] == 0) {
          mp[k]++;
          s[k] = a;
          mp1[k] = 1;
        }
      }
  }
  cin >> n;
  while (n--) {
    cin >> a;
    if (mp[a] == 0)
      cout << "0 -" << endl;
    else
      cout << mp[a] << " " << s[a] << endl;
  }
}
