#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1061109567;
const ll INF = 4557430888798830399;
const int MOD = 1e9 + 7;
int n, m, q;
int w[12];
int cnt[1 << 12];
int ans[1 << 12][101];
vector<int> vt[105];
pair<int, int> query[500000];
int val[1 << 12];
int main() {
  cin.tie(0)->sync_with_stdio(0);
  if (fopen(""
            ".in",
            "r")) {
    freopen(
        ""
        ".in",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  cin >> n >> m >> q;
  for (int i = 0; i < n; ++i) cin >> w[i];
  for (int i = 0; i < m; ++i) {
    int cur = 0;
    for (int j = 0; j < n; ++j) {
      char ch;
      cin >> ch;
      if (ch == '1') cur |= 1 << j;
    }
    ++cnt[cur];
  }
  for (int i = 0; i < q; ++i) {
    int cur = 0;
    for (int j = 0; j < n; ++j) {
      char ch;
      cin >> ch;
      if (ch == '1') cur |= 1 << j;
    }
    int k;
    cin >> k;
    query[i] = {cur, k};
    vt[k].emplace_back(cur);
  }
  for (int mask = 0; mask < (1 << n); ++mask) {
    for (int i = 0; i < n; ++i)
      if ((((mask) >> (i)) & 1)) val[mask] += w[i];
  }
  memset(ans, -1, sizeof(ans));
  for (int k = 0; k <= 100; ++k)
    for (auto state : vt[k]) {
      if (ans[state][k] == -1) {
        ans[state][k] = 0;
        for (int mask = 0; mask < (1 << n); ++mask) {
          int curstate = state ^ mask;
          curstate = ~curstate & ((1 << n) - 1);
          if (val[curstate] <= k) ans[state][k] += cnt[mask];
        }
      }
    }
  for (int i = 0; i < q; ++i)
    cout << ans[query[i].first][query[i].second] << "\n";
  return 0;
}
