#include <bits/stdc++.h>
using namespace std;
string s[10005];
map<string, int> mp1;
map<string, int> mp2;
map<string, int> mp3;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    int len = s[i].size();
    mp3.clear();
    string ss = "";
    for (int j = 0; j < len; j++) {
      ss = "";
      for (int k = j; k < len; k++) {
        ss = ss + s[i][k];
        if (!mp3[ss]) {
          mp1[ss]++;
          mp2[ss] = i;
        }
        mp3[ss] = 1;
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    string m;
    cin >> m;
    if (mp1[m])
      cout << mp1[m] << ' ' << s[mp2[m]] << endl;
    else
      cout << "0 -" << endl;
  }
}
