#include <bits/stdc++.h>
using namespace std;
class trie {
 public:
  map<char, trie> h;
  bool e;
  int n_id;
  int k;
  trie() : e(false), k(0), n_id(-1){};
  void insert(const string &x, int id) {
    trie *p = this;
    for (char c : x) {
      p = &p->h[c];
      p->e = true;
      if (p->n_id != id) {
        p->n_id = id;
        p->k++;
      }
    }
  }
  bool _find(const string &x, int &id) {
    trie *p = this;
    int ans(0);
    bool existe = 1;
    for (char c : x) {
      if (p->h.find(c) != p->h.end())
        p = &p->h[c];
      else
        return false;
    }
    if (p->e) {
      id = p->n_id;
      ans = p->k;
      cout << ans << " ";
      return true;
    }
    return false;
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  trie t;
  string p;
  int n;
  cin >> n;
  int id(0);
  vector<string> txt(n);
  for (int i = 0; i < n; ++i) {
    cin >> txt[i];
    for (int j = 0; j < txt[i].size(); ++j)
      t.insert(txt[i].substr(j, txt[i].size() - j), i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> p;
    if (t._find(p, id))
      cout << txt[id] << "\n";
    else
      cout << 0 << " -"
           << "\n";
  }
}
