#include <bits/stdc++.h>
using namespace std;
int n, T;
map<string, int> M;
map<string, bool> MM;
map<string, string> Pre;
int main() {
  cin >> n;
  string s;
  while (n--) {
    cin >> s;
    MM.clear();
    for (int i = 0; i < s.size(); i++) {
      string str = "";
      for (int j = i; j < s.size(); j++) {
        str += s[j];
        if (MM[str] == false) {
          MM[str] = true;
          M[str]++;
          Pre[str] = s;
        }
      }
    }
  }
  cin >> T;
  while (T--) {
    cin >> s;
    if (M[s] == 0)
      cout << 0 << " -\n";
    else
      cout << M[s] << ' ' << Pre[s] << "\n";
  }
}
