#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
string tmp;
string src[N];
int main() {
  int n, m;
  cin >> n;
  map<string, int> mp;
  map<string, string> mps;
  for (int i = 1; i <= n; ++i) {
    cin >> tmp;
    set<string> ss;
    for (int j = 0; j < tmp.size(); ++j) {
      for (int k = 1; k <= tmp.size() - j; ++k) {
        string subt = tmp.substr(j, k);
        ss.insert(subt);
      }
    }
    for (set<string>::iterator it = ss.begin(); it != ss.end(); ++it) {
      ++mp[*it];
      if (mp[*it] == 1) {
        mps[*it] = tmp;
      }
    }
  }
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> tmp;
    if (mp[tmp] == 0) {
      cout << "0 -" << endl;
    } else {
      cout << mp[tmp] << " " << mps[tmp] << endl;
    }
  }
  return 0;
}
