#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> x;
  map<string, int> y;
  int n;
  string s[100005];
  cin >> n;
  string t1 = "st";
  int f = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    int n1 = s[i].size();
    string a = "";
    map<string, int> y1;
    for (int i1 = 0; i1 < n1; i1++) {
      a = "";
      for (int j1 = i1; j1 < n1; j1++) {
        a += s[i][j1];
        if (y1[a] == 0) {
          x[a] = s[i];
          y[a]++;
          y1[a] = 1;
        }
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    string t;
    cin >> t;
    if (y[t] == 0)
      cout << "0 -" << endl;
    else
      cout << y[t] << " " << x[t] << endl;
  }
  return 0;
}
