Problem: Childan is making up a legendary story and trying to sell his forgery — a necklace with a strong sense of "Wu" to the Kasouras. But Mr. Kasoura is challenging the truth of Childan's story. So he is going to ask a few questions about Childan's so-called "personal treasure" necklace.

This "personal treasure" is a multiset S of m "01-strings".

A "01-string" is a string that contains n characters "0" and "1". For example, if n=4, strings "0110", "0000", and "1110" are "01-strings", but "00110" (there are 5 characters, not 4) and "zero" (unallowed characters) are not.

Note that the multiset S can contain equal elements.

Frequently, Mr. Kasoura will provide a "01-string" t and ask Childan how many strings s are in the multiset S such that the "Wu" value of the pair (s, t) is not greater than k. 

Mrs. Kasoura and Mr. Kasoura think that if s_i = t_i (1≤ i≤ n) then the "Wu" value of the character pair equals to w_i, otherwise 0. The "Wu" value of the "01-string" pair is the sum of the "Wu" values of every character pair. Note that the length of every "01-string" is equal to n.

For example, if w=[4, 5, 3, 6], "Wu" of ("1001", "1100") is 7 because these strings have equal characters only on the first and third positions, so w_1+w_3=4+3=7.

You need to help Childan to answer Mr. Kasoura's queries. That is to find the number of strings in the multiset S such that the "Wu" value of the pair is not greater than k.

Input

The first line contains three integers n, m, and q (1≤ n≤ 12, 1≤ q, m≤ 5⋅ 10^5) — the length of the "01-strings", the size of the multiset S, and the number of queries.

The second line contains n integers w_1, w_2, …, w_n (0 ≤ w_i ≤ 100) — the value of the i-th caracter.

Each of the next m lines contains the "01-string" s of length n — the string in the multiset S.

Each of the next q lines contains the "01-string" t of length n and integer k (0≤ k≤ 100) — the query.

Output

For each query, print the answer for this query.

Examples

Input

2 4 5
40 20
01
01
10
11
00 20
00 40
11 20
11 40
11 60


Output

2
4
2
3
4


Input

1 2 4
100
0
1
0 0
0 100
1 0
1 100


Output

1
2
1
2

Note

In the first example, we can get:

"Wu" of ("01", "00") is 40.

"Wu" of ("10", "00") is 20.

"Wu" of ("11", "00") is 0.

"Wu" of ("01", "11") is 20.

"Wu" of ("10", "11") is 40.

"Wu" of ("11", "11") is 60.

In the first query, pairs ("11", "00") and ("10", "00") satisfy the condition since their "Wu" is not greater than 20.

In the second query, all strings satisfy the condition.

In the third query, pairs ("01", "11") and ("01", "11") satisfy the condition. Note that since there are two "01" strings in the multiset, the answer is 2, not 1.

In the fourth query, since k was increased, pair ("10", "11") satisfies the condition too.

In the fifth query, since k was increased, pair ("11", "11") satisfies the condition too.

Solution (in JAVA):

Solution:
import java.util.*;
import java.util.stream.*;
import java.util.function.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;
import static java.util.Comparator.*;
import static java.lang.Math.*;
public class Main {
  public static final PrintWriter outWriter = new PrintWriter(System.out);
  public static final int _BUFFER_SIZE = 1 << 16;
  public static final DataInputStream _din = new DataInputStream(System.in);
  public static final byte[] _buffer = new byte[_BUFFER_SIZE];
  public static int _bufferPointer = 0, _bytesRead = 0;
  public static class Query implements Comparable<Query> {
    public int k;
    public int ndx;
    public int k() { return k; }
    public int ndx() { return ndx; }
    Query(int k, int ndx) { this.k=k; this.ndx=ndx; }
    Query() {
      this(nextInt(),nextInt());
    }
    public static Comparator<Query> cmp = Comparator.comparing(Query::k).thenComparing(Query::ndx);
    public int compareTo(Query o) { return cmp.compare(this, o); }
    public boolean equals(Object oo) {
      @SuppressWarnings("unchecked")
      Query o = (Query)oo;
      return o != null && k==o.k&&ndx==o.ndx;
    }
    public int hashCode() { return Objects.hash(k,ndx); }
    public String toString() { return ""+k+","+ndx; }
  }
  public static class Result implements Comparable<Result> {
    public int wu;
    public int count;
    public int wu() { return wu; }
    public int count() { return count; }
    Result(int wu, int count) { this.wu=wu; this.count=count; }
    Result() {
      this(nextInt(),nextInt());
    }
    public static Comparator<Result> cmp = Comparator.comparing(Result::wu).thenComparing(Result::count);
    public int compareTo(Result o) { return cmp.compare(this, o); }
    public boolean equals(Object oo) {
      @SuppressWarnings("unchecked")
      Result o = (Result)oo;
      return o != null && wu==o.wu&&count==o.count;
    }
    public int hashCode() { return Objects.hash(wu,count); }
    public String toString() { return ""+wu+","+count; }
  }
  public static class Path implements Comparable<Path> {
    public int value;
    public int mask;
    public int value() { return value; }
    public int mask() { return mask; }
    Path(int value, int mask) { this.value=value; this.mask=mask; }
    Path() {
      this(nextInt(),nextInt());
    }
    public static Comparator<Path> cmp = Comparator.comparing(Path::value).thenComparing(Path::mask);
    public int compareTo(Path o) { return cmp.compare(this, o); }
    public boolean equals(Object oo) {
      @SuppressWarnings("unchecked")
      Path o = (Path)oo;
      return o != null && value==o.value&&mask==o.mask;
    }
    public int hashCode() { return Objects.hash(value,mask); }
    public String toString() { return ""+value+","+mask; }
  }
  public static ArrayList<Path> getPath(int[] ws, int NS) {
    ArrayList<Path> out = new ArrayList<Path>();
    HashSet<Integer> visited = new HashSet<Integer>(NS);
    PriorityQueue<Path> pq = new PriorityQueue<Path>();
    int startState = NS-1;
    visited.add(startState);
    pq.offer(new Path(0, startState));
    while (!pq.isEmpty() && pq.peek().value <= 100) {
      Path tmp = pq.poll();
      out.add(tmp);
      for (int i = 0; i < ws.length; i++) {
        int next = tmp.mask ^ (1<<i);
        if (!visited.contains(next)) {
          visited.add(next);
          pq.offer(new Path(tmp.value+ws[ws.length-i-1], next));
        }
      }
    }
    return out;
  }
  public static void main() {
    int N = nextInt(), M = nextInt(), Q = nextInt();
    int NS = 1<<N;
    int[] ws = new int[N];
    for (int i = 0; i < ws.length; i++) {
      ws[i] = nextInt();
    }
    ArrayList<Path> path = getPath(ws, NS);
    int[] strs = new int[NS];
    ArrayList<ArrayList<Query>> queries = new ArrayList<ArrayList<Query>>(NS);
    for (int i = 0; i < NS; i++) { queries.add(new ArrayList<Query>()); }
    for (int i = 0; i < M; i++) {
      strs[Integer.parseInt(next(),2)]++;
    }
    for (int i = 0; i < Q; i++) {
      queries.get(Integer.parseInt(next(),2)).add(new Query(nextInt(), i));
    }
    int[] out = new int[Q];
    for (int q = 0; q < NS; q++) {
      ArrayList<Query> qs = queries.get(q);
      Collections.sort(qs);
      int qsNdx = 0, cumSum = 0;
      for (Path p : path) {
        while (qsNdx < qs.size() && qs.get(qsNdx).k < p.value) {
          out[qs.get(qsNdx++).ndx] = cumSum;
        }
        cumSum += strs[q^p.mask];
      }
      while (qsNdx < qs.size()) {
        out[qs.get(qsNdx++).ndx] = cumSum;
      }
    }
    for (int i : out) {
      outWriter.println(i);
    }
  }
  public static void main(String[] args) { main(); outWriter.flush(); }
  public static void _fillBuffer() {
    try {
      _bytesRead = _din.read(_buffer, _bufferPointer = 0, _buffer.length);
      if (_bytesRead == -1) {
        _buffer[0] = -1;
        throw new UncheckedIOException(new IOException("end of stream"));
      }
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }
  public static byte _read() {
    if (_bufferPointer == _bytesRead)
      _fillBuffer();
    return _buffer[_bufferPointer++];
  }
  public static String next() {
    byte[] strBuf = new byte[64];
    int cnt = 0, c;
    while ((c = _read()) != -1) {
      if (Character.isWhitespace(c)) {
        if (cnt == 0) {
          continue;
        } else {
          break;
        }
      }
      if (strBuf.length == cnt) {
        strBuf = Arrays.copyOf(strBuf, strBuf.length*2);
      }
      strBuf[cnt++] = (byte) c;
    }
    return new String(strBuf, 0, cnt);
  }
  public static String nextLine() {
    byte[] strBuf = new byte[64];
    int cnt = 0, c;
    while ((c = _read()) != -1) {
      if (c == '\n') {
        if (cnt == 0) {
          continue;
        } else {
          break;
        }
      }
      if (strBuf.length == cnt) {
        strBuf = Arrays.copyOf(strBuf, strBuf.length*2);
      }
      strBuf[cnt++] = (byte) c;
    }
    return new String(strBuf, 0, cnt);
  }
  public static int nextInt() {
    int ret = 0;
    byte c = _read();
    while (c <= ' ')
      c = _read();
    boolean neg = (c == '-');
    if (neg)
      c = _read();
    do {
      ret = ret * 10 + c - '0';
    } while ((c = _read()) >= '0' && c <= '9');
    if (neg)
      return -ret;
    return ret;
  }
  public static long nextLong() {
    long ret = 0;
    byte c = _read();
    while (c <= ' ')
      c = _read();
    boolean neg = (c == '-');
    if (neg)
      c = _read();
    do {
      ret = ret * 10 + c - '0';
    } while ((c = _read()) >= '0' && c <= '9');
    if (neg)
      return -ret;
    return ret;
  }
  public static double nextDouble() {
    double ret = 0, div = 1;
    byte c = _read();
    while (c <= ' ')
      c = _read();
    boolean neg = (c == '-');
    if (neg)
      c = _read();
    do {
      ret = ret * 10 + c - '0';
    }
    while ((c = _read()) >= '0' && c <= '9');
    if (c == '.') {
      while ((c = _read()) >= '0' && c <= '9') {
        ret += (c - '0') / (div *= 10);
      }
    }
    if (neg)
      return -ret;
    return ret;
  }
}