#include <bits/stdc++.h>
using namespace std;
map<string, long long> frequency_of_every_substring;
map<string, string> matched_main_string;
int main() {
  long long i, j, m, n, t, k;
  cin >> n;
  vector<string> main_strings(n);
  for (i = 0; i < n; i++) {
    cin >> main_strings[i];
    map<string, long long> temp;
    for (j = 1; j <= main_strings[i].size(); j++) {
      for (k = 0; k < main_strings[i].size(); k++) {
        if (k + j > main_strings[i].size()) break;
        string test_sub_str = main_strings[i].substr(k, j);
        if (temp.find(test_sub_str) == temp.end()) {
          temp[test_sub_str] = 1;
          matched_main_string[test_sub_str] = main_strings[i];
          frequency_of_every_substring[test_sub_str]++;
        }
      }
    }
  }
  long long query;
  cin >> query;
  while (query--) {
    string sub_str;
    cin >> sub_str;
    if (frequency_of_every_substring[sub_str] == 0)
      cout << 0 << " -" << endl;
    else {
      cout << frequency_of_every_substring[sub_str] << " "
           << matched_main_string[sub_str] << endl;
    }
  }
}
