#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O2")
template <typename T>
void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
  x = min(x, y);
}
const int LIM = 2e5 + 5, MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n;
  map<string, set<long long> > make_pair;
  string str[n];
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    str[i] = s;
    for (int j = 0; j < s.size(); j++) {
      string ab = "";
      for (int t = j; t < s.size(); t++) {
        ab += s[t];
        make_pair[ab].insert(i);
      }
    }
  }
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    if (make_pair[s].size()) {
      cout << make_pair[s].size() << " " << str[*make_pair[s].begin()] << "\n";
    } else
      cout << "0 -"
           << "\n";
  }
}
