#include <bits/stdc++.h>
using namespace std;
map<string, int> mp1, mp3;
map<string, string> mp2;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.length(); j++)
      for (int l = 1; l + j - 1 < s.length(); l++)
        if (mp2[s.substr(j, l)] != s) {
          mp1[s.substr(j, l)]++;
          mp2[s.substr(j, l)] = s;
        }
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    cout << mp1[s] << ' ';
    if (mp1[s] == 0)
      cout << '-' << endl;
    else
      cout << mp2[s] << endl;
  }
  return 0;
}
