#include <bits/stdc++.h>
using namespace std;
map<string, string> x;
map<string, vector<int>> values;
int main() {
  ios ::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    int len = (int)str.size();
    for (int j = 0; j < len; j++) {
      string sub = "";
      for (int k = j; k < len; k++) {
        sub += str[k];
        if (!x.count(sub)) x[sub] = str;
        values[sub].push_back(i);
      }
    }
  }
  for (auto e : values) {
    string key = e.first;
    sort(values[key].begin(), values[key].end());
    values[key].resize(unique(values[key].begin(), values[key].end()) -
                       values[key].begin());
  }
  int q;
  cin >> q;
  while (q--) {
    string str;
    cin >> str;
    int occurences = values[str].size();
    cout << occurences << ' ';
    if (occurences > 0) {
      cout << x[str] << endl;
    } else {
      cout << "-" << endl;
    }
  }
}
