#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
int n, m;
map<string, int> ans;
map<string, string> vis;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int x = 1; x <= n; ++x) {
    string a;
    cin >> a;
    int len = a.size();
    map<string, int> temp;
    for (int i = 0; i < len; ++i) {
      for (int j = 1; i + j - 1 < len; j++) {
        string s = a.substr(i, j);
        if (!temp[s]) temp[s] = 1, ans[s]++;
        vis[s] = a;
      }
    }
  }
  cin >> m;
  while (m--) {
    string a;
    cin >> a;
    if (!ans[a]) {
      cout << "0 -" << endl;
    } else {
      cout << ans[a] << " " << vis[a] << endl;
    }
  }
  return 0;
}
