#include <bits/stdc++.h>
using namespace std;
clock_t __START, __END;
double __TOTALTIME;
void _MS() { __START = clock(); }
void _ME() {
  __END = clock();
  __TOTALTIME = (double)(__END - __START) / CLOCKS_PER_SEC;
  cout << "Time: " << __TOTALTIME << " s" << endl;
}
const double E = 2.718281828;
const double PI = acos(-1.0);
const long long INF = (1LL << 60);
const int inf = (1 << 30);
const double ESP = 1e-9;
const int mod = (int)1e9 + 7;
const int N = (int)1e6 + 10;
map<string, pair<int, int> > mp;
map<string, bool> mark;
string a[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    string temp;
    cin >> temp;
    a[i] = temp;
    int l = temp.length();
    mark.clear();
    for (int j = 0; j < l; ++j) {
      for (int k = 1; k + j <= l; ++k) {
        string tt = temp.substr(j, k);
        if (mark[tt]) continue;
        mark[tt] = 1;
        if (mp[tt].first == 0)
          mp[tt].first = i, mp[tt].second = 1;
        else
          mp[tt].second++;
      }
    }
  }
  int m;
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    string temp;
    cin >> temp;
    if (mp[temp].first)
      cout << mp[temp].second << ' ' << a[mp[temp].first] << endl;
    else
      cout << "0 -" << endl;
  }
  return 0;
}
