#include <bits/stdc++.h>
using namespace std;
set<pair<string, int> > str;
string all[10100];
int main() {
  int n;
  cin >> n;
  for (int k = 0; k < n; k++) {
    string p;
    cin >> p;
    all[k] = p;
    int len = p.length();
    for (int i = 0; i < len; i++) {
      for (int j = 1; i + j <= len; j++) {
        str.insert(pair<string, int>(p.substr(i, j), k));
      }
    }
  }
  vector<string> strs;
  vector<int> index;
  for (auto iter = str.begin(); iter != str.end(); iter++) {
    strs.push_back(iter->first);
    index.push_back(iter->second);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string query;
    cin >> query;
    int res = binary_search(strs.begin(), strs.end(), query);
    if (res == 1) {
      int upper = upper_bound(strs.begin(), strs.end(), query) - strs.begin();
      int ans = upper_bound(strs.begin(), strs.end(), query) -
                lower_bound(strs.begin(), strs.end(), query);
      cout << ans << " " << all[index[upper - 1]] << "\n";
    } else {
      cout << "0 - \n";
    }
  }
  return 0;
}
