#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
static inline int ctz(unsigned x) { return __builtin_ctz(x); }
static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
static inline int clz(unsigned x) { return __builtin_clz(x); }
static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }
static inline int popcnt(unsigned x) { return __builtin_popcount(x); }
static inline int popcntll(unsigned long long x) {
  return __builtin_popcountll(x);
}
static inline int bsr(unsigned x) { return 31 ^ clz(x); }
static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
string f[10000];
string s[50000];
unordered_map<string, pair<int, int> > mp;
int main() {
  canhazfast();
  int n, q;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> f[i];
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> s[i];
    mp[s[i]] = {0, -1};
  }
  for (int i = 0; i < n; ++i) {
    unordered_set<string> fs;
    int sz = (int)f[i].size();
    for (int b = 0; b < sz; ++b) {
      for (int e = b + 1; e <= sz; ++e) fs.insert(f[i].substr(b, e - b));
    }
    for (const string &x : fs) {
      if (mp.count(x)) ++mp[x].first, mp[x].second = i;
    }
  }
  for (int i = 0; i < q; ++i) {
    int c, id;
    tie(c, id) = mp[s[i]];
    cout << c << ' ';
    if (id < 0)
      cout << "-\n";
    else
      cout << f[id] << '\n';
  }
  return 0;
}
