// #pragma GCC optimize("Ofast,unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

// #pragma GCC target("avx,avx2,fma")

#define all(x) std::begin(x), std::end(x)
#define isz(x) (int)std::size(x)

const auto ready = []() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.tie(0);
  std::cout << std::fixed << std::setprecision(12);
  return 1;
};

const auto TEST = []() { freopen("in.txt", "r", stdin); };

using ll = long long;
using ull = unsigned long long;
using ld = long double;

template <typename C>
void reuniq(C& c) {
  c.erase(unique(all(c)), end(c));
}

template <typename C, typename X>
int lowpos(const C& c, X x) {
  return int(lower_bound(all(c), x) - begin(c));
}

template <typename C, typename X>
int uppos(const C& c, X x) {
  return int(upper_bound(all(c), x) - begin(c));
}

template <typename X, typename Y>
X& remin(X& x, const Y& y) {
  return x = (y < x) ? y : x;
}

template <typename X, typename Y>
X& remax(X& x, const Y& y) {
  return x = (x < y) ? y : x;
}

void Solve() {
  int n, q, w;
  cin >> n >> q >> w;
  vector<pair<string, int>> a(n);
  for (int i = 0; i < n; ++i) {
    auto& [s, j] = a[i];
    cin >> s;
    j = i + 1;
  }
  sort(all(a));
  // пусть маска означает какие буквы есть в слове
  // сохраним для каждой маски индекс строки такой \
     что для какой то из подмасок существует строка \
     из массива а которая представима этой маской
  vector<int> dp(1 << 20, n);
  for (int i = 0; i < n; ++i) {
    const auto& [s, _] = a[i];
    bitset<20> mask = 0;
    for (auto c : s) mask |= 1 << (c - 'a');
    // здесь у нас база
    remin(dp[(mask).to_ulong()], i);
  }
  for (int i = 0; i < (1 << 20); ++i) {
    for (int j = 0; j < 20; ++j) {
      // ставим текущий бит -> получаем надмаску \
         тем самым делаем условие 86 строки
      remin(dp[i | (1 << j)], dp[i]);
    }
  }
  while (q --> 0) {
    string s;
    cin >> s;
    bitset<20> mask = 0;
    for (auto c : s) mask |= 1 << (c - 'a');
    // берем ~маску так как нам нужен ответ не для самой маски(так как это будет полное пересечение) \
       а пытаемся найти любую маску которая есть в массиве \
       что у нас и предпосчитано в дп
    cout << (dp[(~mask).to_ulong()] == n ? -1 : a[dp[(~mask).to_ulong()]].second) << '\n';
  }
}

signed main() {
  ready();
  Solve();
}