#include <bits/stdc++.h>
int siz;
struct que {
  int l, r, id;
  inline bool operator<(const que& rhs) const {
    return (l / siz != rhs.l / siz) ? (l < rhs.l) : (r < rhs.r);
  }
} q[188888];
char S[10005][10], t[10];
int s[188888], n, m, fx = 127, ys[188888], x[188888], y[188888], c[188888],
                     sa[188888], height[188888], p[188888], st[18][188888], Q,
                     len;
int ans1[188888], ans2[188888];
void sort() {
  int m = fx;
  for (int i = 0; i <= m; ++i) c[i] = 0;
  for (int i = 1; i <= n; ++i) ++c[x[i] = s[i]];
  for (int i = 1; i <= m; ++i) c[i] += c[i - 1];
  for (int i = n; i; --i) sa[c[x[i]]--] = i;
  for (int k = 1; k <= n; k <<= 1) {
    int p = 0;
    for (int i = n - k + 1; i <= n; ++i) y[++p] = i;
    for (int i = 1; i <= n; ++i)
      if (sa[i] - k > 0) y[++p] = sa[i] - k;
    for (int i = 0; i <= m; ++i) c[i] = 0;
    for (int i = 1; i <= n; ++i) ++c[x[i]];
    for (int i = 1; i <= m; ++i) c[i] += c[i - 1];
    for (int i = n; i; --i) sa[c[x[y[i]]]--] = y[i];
    std::swap(x, y);
    x[sa[1]] = p = 1;
    for (int i = 2; i <= n; ++i)
      x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k])
                     ? p
                     : ++p;
    if (p == n) break;
    m = p;
  }
  for (int i = 1, k = 0; i <= n; ++i)
    if (x[i] != 1) {
      k -= !!k;
      int j = sa[x[i] - 1];
      while (s[i + k] == s[j + k]) ++k;
      height[x[i]] = k;
    }
}
void init() {
  for (int i = 1; i <= n; ++i) p[i] = ys[sa[i]];
  for (int i = 1; i <= n; ++i) st[0][i] = height[i];
  for (int i = 0; i < 17; ++i)
    for (int j = 1; (1 << i) + j <= n; ++j)
      st[i + 1][j] = std::min(st[i][j], st[i][j + (1 << i)]);
}
inline int ask(int l, int r) {
  int lg = (31 - __builtin_clz(r - l + 1));
  return std::min(st[lg][l], st[lg][r - (1 << lg) + 1]);
}
bool chk(int w) {
  for (int i = 0; i < len; ++i)
    if (s[w + i] != t[i]) return s[w + i] < t[i];
  return 1;
}
int findl(int wz, int len) {
  int l = 1, r = wz - 1, ans = wz;
  while (l <= r) {
    const int mid = l + r >> 1;
    if (ask(mid + 1, wz) >= len)
      r = (ans = mid) - 1;
    else
      l = mid + 1;
  }
  return ans;
}
int findr(int wz, int len) {
  int l = wz + 1, r = n, ans = wz;
  while (l <= r) {
    const int mid = l + r >> 1;
    if (ask(wz + 1, mid) >= len)
      l = (ans = mid) + 1;
    else
      r = mid - 1;
  }
  return ans;
}
void MD() {
  if (m == 0) return;
  siz = n / sqrt(m);
  std::sort(q + 1, q + Q + 1);
  static int vis[188888];
  for (int i = 1, l = 1, r = 0, nw = 0; i <= Q; ++i) {
    while (r < q[i].r)
      if (!vis[p[++r]]++) ++nw;
    while (l > q[i].l)
      if (!vis[p[--l]]++) ++nw;
    while (l < q[i].l)
      if (!--vis[p[l++]]) --nw;
    while (r > q[i].r)
      if (!--vis[p[r--]]) --nw;
    ans1[q[i].id] = nw;
  }
}
int main() {
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%s", S[i]);
    for (int j = 0; S[i][j]; ++j) s[++n] = S[i][j], ys[n] = i;
    s[++n] = fx++;
  }
  sort();
  init();
  scanf("%d", &Q);
  for (int i = 1; i <= Q; ++i) {
    scanf("%s", t);
    len = strlen(t);
    int l = 1, r = n, as = n + 1;
    while (l <= r) {
      const int mid = l + r >> 1;
      if (chk(sa[mid]))
        l = (as = mid) + 1;
      else
        r = mid - 1;
    }
    bool ok = 1;
    for (int i = 0; i < len; ++i)
      if (s[sa[as] + i] != t[i]) ok = 0;
    if (!ok)
      q[i] = (que){1, 0, i};
    else {
      int L = findl(as, len), R = findr(as, len);
      q[i] = (que){L, R, i};
      ans2[i] = p[as];
    }
  }
  MD();
  for (int i = 1; i <= Q; ++i) {
    if (ans1[i])
      printf("%d %s\n", ans1[i], S[ans2[i]]);
    else
      puts("0 -");
  }
  return 0;
}
