#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643383;
int w;
int visit[37] = {0};
int Ceil(int a, int b) {
  if (a % b == 0)
    return a / b;
  else
    return (a / b) + 1;
}
struct TrieNode {
  struct TrieNode *children[37];
  bool isEndofWord;
  int cnt[37];
  int snum[37];
  int visit[37];
};
TrieNode *getNode() {
  TrieNode *x = new TrieNode;
  x->isEndofWord = false;
  for (int i = 0; i < (37); ++i) x->children[i] = NULL;
  for (int i = 0; i < (37); ++i) x->cnt[i] = 0;
  for (int i = 0; i < (37); ++i) x->snum[i] = -1;
  for (int i = 0; i < (37); ++i) x->visit[i] = -1;
  return x;
}
int find(char c) {
  if (c == '.') {
    return 26;
  }
  if (c >= 'a' && c <= 'z') {
    return c - 'a';
  }
  return 27 + c - '0';
}
void insert(TrieNode *root, string s, int num) {
  TrieNode *p = root;
  for (int i = 0; i < (s.size()); ++i) {
    int index;
    index = find(s[i]);
    if (!p->children[index]) {
      p->children[index] = getNode();
    }
    if (p->visit[index] != num) p->cnt[index]++;
    p->snum[index] = num;
    p->visit[index] = num;
    p = p->children[index];
  }
  p->isEndofWord = true;
}
int search(TrieNode *root, string s) {
  TrieNode *p = root;
  int ans;
  for (int i = 0; i < (s.size()); ++i) {
    int index;
    index = find(s[i]);
    if (!p->children[index]) {
      return 0;
    }
    ans = p->cnt[index];
    w = p->snum[index];
    p = p->children[index];
  }
  return ans;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int n;
  cin >> n;
  string a[n];
  TrieNode *root = getNode();
  int e = 0;
  while (n--) {
    string s;
    cin >> s;
    a[e] = s;
    e++;
    int y = s.size() - 1;
    for (int i = 0; i < (s.size()); ++i) {
      string str;
      int x = s.size() - i;
      str.resize(x);
      int q = 0;
      for (int j = i; j <= (y); ++j) {
        str[q] = s[j];
        q++;
      }
      insert(root, str, e);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    int y = search(root, s);
    if (y == 0) {
      cout << "0 -" << '\n';
    } else {
      cout << y << " " << a[w - 1] << '\n';
    }
  }
  return 0;
}
