#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector< vii> vvii;

#define FOR(i, a, b) \
    for (int i = (a); i ^ (b); i++)
#define FORE(i, a, b) \
    for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) \
    for (int i = (a); i >= (b); i--)

#define INF 1e9+7
#define INFLL 1e18+7
#define esp 1e-9
#define PI 3.14159265

ll nMod = 1e9 + 7;

inline ll GCD(ll a, ll b) {while (b != 0) {ll c = a % b; a = b; b = c;} return a;};
inline ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;};

int n, m, q;
vi cnt;
vi w;
vector<vii > st;
vvi sum;

int bin2dec(int x) {
    int res = 0;
    int k = 1;
    while (x > 0) {
        res += (x % 10) * k;
        x /= 10;
        k *= 2;
    }
    return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/input", "r", stdin);
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/output", "w", stdout);
    scanf("%d %d %d", &n, &m, &q);
    int nn = 1 << n;
    cnt = vi(nn, 0);
    w = vi(n, 0);
    FORD(i, n-1, 0) {
        scanf("%d", &w[i]);
    }
    st = vector<vii >(nn, vii(nn, {0, 0}));
    sum = vvi(nn, vi(101, 0));
    int x;
    FOR(i, 0, m) {
        scanf("%d", &x);
        x = bin2dec(x);
        cnt[x]++;
    }
    FOR(i, 0, nn) {
        FOR(bit, 0, n) {
            int b = (i >> bit) & 1;
            b <<= bit;
            int lowBits = 0;
            int highBits = 0;
            FOR(j, 0, bit) {
                lowBits |= 1 << j;
            }
            FOR(j, bit, n-1) {
                highBits |= 1 << j;
            }
            FOR(j, 0, 1 << (n-1)) {
                int low = j & lowBits;
                int high = j & highBits;
                high <<= 1;
                int num = low | b | high;
                // cerr << i << " " << bit << " " << j << " " << lowBits << " " << highBits << " " << b << " " << low << " " << high << " " << num << endl;
                st[i][num].first += w[bit];
            }
        }
    }

    FOR(i, 0, nn) {
        FOR(j, 0, nn) {
            if (st[i][j].first <= 100) {
                sum[i][st[i][j].first] += cnt[j];
            }
        }
        FOR(j, 1, 101) {
            // cerr << i << " " << " " << j << " " << sum[i][j] << " ";
            sum[i][j] += sum[i][j-1];
            // cerr << sum[i][j] << endl;
        }
    }

    int y;
    FOR(i, 0, q) {
        scanf("%d %d", &x, &y);
        x = bin2dec(x);
        cout << sum[x][y] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector< vii> vvii;

#define FOR(i, a, b) \
    for (int i = (a); i ^ (b); i++)
#define FORE(i, a, b) \
    for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) \
    for (int i = (a); i >= (b); i--)

#define INF 1e9+7
#define INFLL 1e18+7
#define esp 1e-9
#define PI 3.14159265

ll nMod = 1e9 + 7;

inline ll GCD(ll a, ll b) {while (b != 0) {ll c = a % b; a = b; b = c;} return a;};
inline ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;};

int n, m, q;
vi cnt;
vi w;
vector<vii > st;
vvi sum;

int bin2dec(int x) {
    int res = 0;
    int k = 1;
    while (x > 0) {
        res += (x % 10) * k;
        x /= 10;
        k *= 2;
    }
    return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/input", "r", stdin);
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/output", "w", stdout);
    scanf("%d %d %d", &n, &m, &q);
    int nn = 1 << n;
    cnt = vi(nn, 0);
    w = vi(n, 0);
    FOR(i, 0, n) {
        scanf("%d", &w[n-i-1]);
    }
    st = vector<vii >(nn, vii(nn, {0, 0}));
    sum = vvi(nn, vi(101*12, 0));
    int x;
    FOR(i, 0, m) {
        scanf("%d", &x);
        x = bin2dec(x);
        cnt[x]++;
    }
    FOR(i, 0, nn) {
        FOR(bit, 0, n) {
            int b = (i >> bit) & 1;
            b <<= bit;
            int lowBits = 0;
            int highBits = 0;
            FOR(j, 0, bit) {
                lowBits |= 1 << j;
            }
            FOR(j, bit, n-1) {
                highBits |= 1 << j;
            }
            FOR(j, 0, 1 << (n-1)) {
                int low = j & lowBits;
                int high = j & highBits;
                high <<= 1;
                int num = low | b | high;
                // cerr << i << " " << bit << " " << j << " " << lowBits << " " << highBits << " " << b << " " << low << " " << high << " " << num << endl;
                st[i][num].first += w[bit];
                // cerr << i << " " << num << " " << w[bit] << endl;
            }
        }
    }

    FOR(i, 0, nn) {
        FOR(j, 0, nn) {
            // x = 0;
            // FOR(k, 0, n) {
            //     if (((i >> k) & 1) == ((j >> k) & 1)) {
            //         x += w[k];
            //     }
            // }
            // if (x <= 100) {
            //     sum[i][x] += cnt[j];
            // }

            sum[i][st[i][j].first] += cnt[j];
        }

        FOR(j, 1, 101*12) {
            sum[i][j] += sum[i][j-1];
        }
    }

    int y;
    FOR(i, 0, q) {
        scanf("%d %d", &x, &y);
        x = bin2dec(x);
        cout << sum[x][y] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector< vii> vvii;

#define FOR(i, a, b) \
    for (int i = (a); i < (b); i++)
#define FORE(i, a, b) \
    for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) \
    for (int i = (a); i >= (b); i--)

#define INF 1e9+7
#define INFLL 1e18+7
#define esp 1e-9
#define PI 3.14159265

ll nMod = 1e9 + 7;

inline ll GCD(ll a, ll b) {while (b != 0) {ll c = a % b; a = b; b = c;} return a;};
inline ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;};

int n, m, q;
vi cnt;
vi w;
vector<vii > st;
vvi sum;

int bin2dec(int x) {
    int res = 0;
    int k = 1;
    while (x > 0) {
        res += (x % 10) * k;
        x /= 10;
        k *= 2;
    }
    return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/input", "r", stdin);
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/output", "w", stdout);
    scanf("%d %d %d", &n, &m, &q);
    cnt = vi(1 << n, 0);
    w = vi(n, 0);
    FOR(i, 0, n) {
        scanf("%d", &w[n-i-1]);
    }
    st = vector<vii >(1 << n, vii(1 << n, {0, 0}));
    sum = vvi(1 << n, vi(1 << n, 0));
    int x;
    FOR(i, 0, m) {
        scanf("%d", &x);
        x = bin2dec(x);
        cnt[x]++;
    }

    FOR(i, 0, 1<<n) {
        FOR(bit, 0, n) {
            int b = (i >> bit) & 1;
            b <<= bit;
            int lowBits = 0;
            int highBits = 0;
            FOR(j, 0, bit) {
                lowBits |= 1 << j;
            }
            FOR(j, bit, n-1) {
                highBits |= 1 << j;
            }
            FOR(j, 0, 1 << (n-1)) {
                int low = j & lowBits;
                int high = j & highBits;
                high <<= 1;
                int num = low | b | high;
                // cerr << i << " " << bit << " " << j << " " << lowBits << " " << highBits << " " << b << " " << low << " " << high << " " << num << endl;
                st[i][num].first += w[bit];
                // cerr << i << " " << num << " " << w[bit] << endl;
            }
        }
    }
    // cerr << st[3][3].first << endl;
    FOR(i, 0, 1<<n) {
        FOR(j, 0, 1 << n) {
            // x = 0;
            // FOR(k, 0, n) {
            //     if (((i >> k) & 1) == ((j >> k) & 1)) {
            //         x += w[k];
            //     }
            // }
            // st[i][j] = {x, cnt[j]};
            st[i][j].second = cnt[j];
        }
        sort(st[i].begin(), st[i].end());
        sum[i][0] = st[i][0].second;
        // cerr << st[i][0].second << endl;
        FOR(j, 1, 1 << n) {
            sum[i][j] = st[i][j].second + sum[i][j-1];
        }
    }

    int y;
    FOR(i, 0, q) {
        scanf("%d %d", &x, &y);
        x = bin2dec(x);
        y++;
        vii::iterator it = lower_bound(st[x].begin(), st[x].end(), make_pair(y, 0)) - 1;
        int index = distance(st[x].begin(), it);
        // cerr << index << endl;
        cout << sum[x][index] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector< vii> vvii;

#define FOR(i, a, b) \
    for (int i = (a); i < (b); i++)
#define FORE(i, a, b) \
    for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) \
    for (int i = (a); i >= (b); i--)

#define INF 1e9+7
#define INFLL 1e18+7
#define esp 1e-9
#define PI 3.14159265

ll nMod = 1e9 + 7;

inline ll GCD(ll a, ll b) {while (b != 0) {ll c = a % b; a = b; b = c;} return a;};
inline ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;};

int n, m, q;
vi cnt;
vi w;
vector<vii > st;
vvi sum;

int bin2dec(int x) {
    int res = 0;
    int k = 1;
    while (x > 0) {
        res += (x % 10) * k;
        x /= 10;
        k *= 2;
    }
    return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/input", "r", stdin);
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/output", "w", stdout);
    scanf("%d %d %d", &n, &m, &q);
    cnt = vi(1 << n, 0);
    w = vi(n, 0);
    FOR(i, 0, n) {
        scanf("%d", &w[n-i-1]);
    }
    st = vector<vii >(1 << n, vii(1 << n, {0, 0}));
    sum = vvi(1 << n, vi(101, 0));
    int x;
    FOR(i, 0, m) {
        scanf("%d", &x);
        x = bin2dec(x);
        cnt[x]++;
    }
    FOR(i, 0, 1<<n) {
        FOR(bit, 0, n) {
            int b = (i >> bit) & 1;
            b <<= bit;
            int lowBits = 0;
            int highBits = 0;
            FOR(j, 0, bit) {
                lowBits |= 1 << j;
            }
            FOR(j, bit, n-1) {
                highBits |= 1 << j;
            }
            FOR(j, 0, 1 << (n-1)) {
                int low = j & lowBits;
                int high = j & highBits;
                high <<= 1;
                int num = low | b | high;
                // cerr << i << " " << bit << " " << j << " " << lowBits << " " << highBits << " " << b << " " << low << " " << high << " " << num << endl;
                st[i][num].first += w[bit];
                // cerr << i << " " << num << " " << w[bit] << endl;
            }
        }
    }

    FOR(i, 0, 1<<n) {
        FOR(j, 0, 1 << n) {
            x = 0;
            FOR(k, 0, n) {
                if (((i >> k) & 1) == ((j >> k) & 1)) {
                    x += w[k];
                }
            }
            if (x <= 100) {
                sum[i][x] += cnt[j];
            }
        }

        FOR(j, 1, 101) {
            sum[i][j] += sum[i][j-1];
        }
    }

    int y;
    FOR(i, 0, q) {
        scanf("%d %d", &x, &y);
        x = bin2dec(x);
        cout << sum[x][y] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector< vii> vvii;

#define FOR(i, a, b) \
    for (int i = (a); i ^ (b); i++)
#define FORE(i, a, b) \
    for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) \
    for (int i = (a); i >= (b); i--)

#define INF 1e9+7
#define INFLL 1e18+7
#define esp 1e-9
#define PI 3.14159265

ll nMod = 1e9 + 7;

inline ll GCD(ll a, ll b) {while (b != 0) {ll c = a % b; a = b; b = c;} return a;};
inline ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;};

int n, m, q;
vi cnt;
vi w;
vector<vii > st;
vvi sum;

int bin2dec(int x) {
    int res = 0;
    int k = 1;
    while (x > 0) {
        res += (x % 10) * k;
        x /= 10;
        k *= 2;
    }
    return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/input", "r", stdin);
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/output", "w", stdout);
    scanf("%d %d %d", &n, &m, &q);
    int nn = 1 << n;
    cnt = vi(nn, 0);
    w = vi(n, 0);
    FOR(i, 0, n) {
        scanf("%d", &w[n-i-1]);
    }
    st = vector<vii >(nn, vii(nn, {0, 0}));
    sum = vvi(nn, vi(101, 0));
    int x;
    FOR(i, 0, m) {
        scanf("%d", &x);
        x = bin2dec(x);
        cnt[x]++;
    }
    // FOR(i, 0, nn) {
    //     FOR(bit, 0, n) {
    //         int b = (i >> bit) & 1;
    //         b <<= bit;
    //         int lowBits = 0;
    //         int highBits = 0;
    //         FOR(j, 0, bit) {
    //             lowBits |= 1 << j;
    //         }
    //         FOR(j, bit, n-1) {
    //             highBits |= 1 << j;
    //         }
    //         FOR(j, 0, 1 << (n-1)) {
    //             int low = j & lowBits;
    //             int high = j & highBits;
    //             high <<= 1;
    //             int num = low | b | high;
    //             // cerr << i << " " << bit << " " << j << " " << lowBits << " " << highBits << " " << b << " " << low << " " << high << " " << num << endl;
    //             st[i][num].first += w[bit];
    //             // cerr << i << " " << num << " " << w[bit] << endl;
    //         }
    //     }
    // }

    FOR(i, 0, nn) {
        FOR(j, 0, nn) {
            x = 0;
            FOR(k, 0, n) {
                if (((i >> k) & 1) == ((j >> k) & 1)) {
                    x += w[k];
                }
            }
            if (x <= 100) {
                sum[i][x] += cnt[j];
            }
        }

        FOR(j, 1, 101) {
            sum[i][j] += sum[i][j-1];
        }
    }

    int y;
    FOR(i, 0, q) {
        scanf("%d %d", &x, &y);
        x = bin2dec(x);
        cout << sum[x][y] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector< vii> vvii;

#define FOR(i, a, b) \
    for (int i = (a); i ^ (b); i++)
#define FORE(i, a, b) \
    for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) \
    for (int i = (a); i >= (b); i--)

#define INF 1e9+7
#define INFLL 1e18+7
#define esp 1e-9
#define PI 3.14159265

ll nMod = 1e9 + 7;

inline ll GCD(ll a, ll b) {while (b != 0) {ll c = a % b; a = b; b = c;} return a;};
inline ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;};

int n, m, q;
vi cnt;
vi w;
vector<vii > st;
vvi sum;

int bin2dec(ll x) {
    int res = 0;
    int k = 1;
    while (x > 0) {
        res += (x % 10) * k;
        x /= 10;
        k *= 2;
    }
    return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/input", "r", stdin);
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/output", "w", stdout);
    scanf("%d %d %d", &n, &m, &q);
    int nn = 1 << n;
    cnt = vi(nn, 0);
    w = vi(n, 0);
    FORD(i, n-1, 0) {
        scanf("%d", &w[i]);
    }
    st = vector<vii >(nn, vii(nn, {0, 0}));
    sum = vvi(nn, vi(101, 0));
    ll x;
    FOR(i, 0, m) {
        scanf("%lld", &x);
        x = bin2dec(x);
        cnt[x]++;
    }
    FOR(i, 0, nn) {
        FOR(bit, 0, n) {
            int b = (i >> bit) & 1;
            b <<= bit;
            int lowBits = 0;
            int highBits = 0;
            FOR(j, 0, bit) {
                lowBits |= 1 << j;
            }
            FOR(j, bit, n-1) {
                highBits |= 1 << j;
            }
            FOR(j, 0, 1 << (n-1)) {
                int low = j & lowBits;
                int high = j & highBits;
                high <<= 1;
                int num = low | b | high;
                // cerr << i << " " << bit << " " << j << " " << lowBits << " " << highBits << " " << b << " " << low << " " << high << " " << num << endl;
                st[i][num].first += w[bit];
            }
        }
    }

    FOR(i, 0, nn) {
        FOR(j, 0, nn) {
            if (st[i][j].first <= 100) {
                sum[i][st[i][j].first] += cnt[j];
            }
        }
        FOR(j, 1, 101) {
            // cerr << i << " " << " " << j << " " << sum[i][j] << " ";
            sum[i][j] += sum[i][j-1];
            // cerr << sum[i][j] << endl;
        }
    }

    int y;
    FOR(i, 0, q) {
        scanf("%lld %d", &x, &y);
        x = bin2dec(x);
        cout << sum[x][y] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector< vii> vvii;

#define FOR(i, a, b) \
    for (int i = (a); i ^ (b); i++)
#define FORE(i, a, b) \
    for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) \
    for (int i = (a); i >= (b); i--)

#define INF 1e9+7
#define INFLL 1e18+7
#define esp 1e-9
#define PI 3.14159265

ll nMod = 1e9 + 7;

inline ll GCD(ll a, ll b) {while (b != 0) {ll c = a % b; a = b; b = c;} return a;};
inline ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;};

int n, m, q;
vi cnt;
vi w;
vector<vii > st;
vvi sum;

int bin2dec(ll x) {
    int res = 0;
    int k = 1;
    while (x > 0) {
        res += (x % 10) * k;
        x /= 10;
        k *= 2;
    }
    return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/input", "r", stdin);
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/output", "w", stdout);
    scanf("%d %d %d", &n, &m, &q);
    int nn = 1 << n;
    cnt = vi(nn, 0);
    w = vi(n, 0);
    FORD(i, n-1, 0) {
        scanf("%d", &w[i]);
    }
    st = vector<vii >(nn, vii(nn, {0, 0}));
    sum = vvi(nn, vi(101, 0));
    ll x;
    FOR(i, 0, m) {
        scanf("%lld", &x);
        x = bin2dec(x);
        cnt[x]++;
    }
    FOR(i, 0, nn) {
        FOR(bit, 0, n) {
            int b = (i >> bit) & 1;
            b <<= bit;
            int lowBits = 0;
            int highBits = 0;
            FOR(j, 0, bit) {
                lowBits |= 1 << j;
            }
            FOR(j, bit, n-1) {
                highBits |= 1 << j;
            }
            FOR(j, 0, 1 << (n-1)) {
                int low = j & lowBits;
                int high = j & highBits;
                high <<= 1;
                int num = low | b | high;
                // cerr << i << " " << bit << " " << j << " " << lowBits << " " << highBits << " " << b << " " << low << " " << high << " " << num << endl;
                st[i][num].first += w[bit];
            }
        }
    }

    FOR(i, 0, nn) {
        FOR(j, 0, nn) {
            if (st[i][j].first <= 100) {
                sum[i][st[i][j].first] += cnt[j];
            }
        }
        FOR(j, 1, 101) {
            sum[i][j] += sum[i][j-1];
        }
    }

    int y;
    FOR(i, 0, q) {
        scanf("%lld %d", &x, &y);
        x = bin2dec(x);
        cout << sum[x][y] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector< vii> vvii;

#define FOR(i, a, b) \
    for (int i = (a); i < (b); i++)
#define FORE(i, a, b) \
    for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) \
    for (int i = (a); i >= (b); i--)

#define INF 1e9+7
#define INFLL 1e18+7
#define esp 1e-9
#define PI 3.14159265

ll nMod = 1e9 + 7;

inline ll GCD(ll a, ll b) {while (b != 0) {ll c = a % b; a = b; b = c;} return a;};
inline ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;};

int n, m, q;
vi cnt;
vi w;
vector<vii > st;
vvi sum;

int bin2dec(int x) {
    int res = 0;
    int k = 1;
    while (x > 0) {
        res += (x % 10) * k;
        x /= 10;
        k *= 2;
    }
    return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	freopen("/Users/macbook/Desktop/MyCPPLibrary/input", "r", stdin);
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/output", "w", stdout);
    scanf("%d %d %d", &n, &m, &q);
    cnt = vi(1 << n, 0);
    w = vi(n, 0);
    FOR(i, 0, n) {
        scanf("%d", &w[n-i-1]);
    }
    st = vector<vii >(1 << n, vii(101, {0, 0}));
    sum = vvi(1 << n, vi(101, 0));
    int x;
    FOR(i, 0, m) {
        scanf("%d", &x);
        x = bin2dec(x);
        cnt[x]++;
    }
    FOR(i, 0, 1<<n) {
        FOR(bit, 0, n) {
            int b = (i >> bit) & 1;
            b <<= bit;
            int lowBits = 0;
            int highBits = 0;
            FOR(j, 0, bit) {
                lowBits |= 1 << j;
            }
            FOR(j, bit, n-1) {
                highBits |= 1 << j;
            }
            FOR(j, 0, 1 << (n-1)) {
                int low = j & lowBits;
                int high = j & highBits;
                high <<= 1;
                int num = low | b | high;
                // cerr << i << " " << bit << " " << j << " " << lowBits << " " << highBits << " " << b << " " << low << " " << high << " " << num << endl;
                st[i][num].first += w[bit];
                // cerr << i << " " << num << " " << w[bit] << endl;
            }
        }
    }
    // cerr << st[3][3].first << endl;
    FOR(i, 0, 1<<n) {
        FOR(j, 0, 1 << n) {
            // x = 0;
            // FOR(k, 0, n) {
            //     if (((i >> k) & 1) == ((j >> k) & 1)) {
            //         x += w[k];
            //     }
            // }
            // st[i][j] = {x, cnt[j]};
            // st[i][j].second = cnt[j];
            if (st[i][j].first <= 100) {
                sum[i][st[i][j].first] += cnt[j];
            }
        }
        // sort(st[i].begin(), st[i].end());
        // sum[i][0] = st[i][0].second;

        // cerr << st[i][0].second << endl;
        FOR(j, 1, 101) {
            sum[i][j] += sum[i][j-1];
        }
    }

    int y;
    FOR(i, 0, q) {
        scanf("%d %d", &x, &y);
        x = bin2dec(x);
        // y++;
        // vii::iterator it = lower_bound(st[x].begin(), st[x].end(), make_pair(y, 0)) - 1;
        // int index = distance(st[x].begin(), it);
        // cerr << index << endl;
        cout << sum[x][y] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector< vii> vvii;

#define FOR(i, a, b) \
    for (int i = (a); i < (b); i++)
#define FORE(i, a, b) \
    for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) \
    for (int i = (a); i >= (b); i--)

#define INF 1e9+7
#define INFLL 1e18+7
#define esp 1e-9
#define PI 3.14159265

ll nMod = 1e9 + 7;

inline ll GCD(ll a, ll b) {while (b != 0) {ll c = a % b; a = b; b = c;} return a;};
inline ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;};

int n, m, q;
vi cnt;
vi w;
vector<vii > st;
vvi sum;

int bin2dec(int x) {
    int res = 0;
    int k = 1;
    while (x > 0) {
        res += (x % 10) * k;
        x /= 10;
        k *= 2;
    }
    return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/input", "r", stdin);
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/output", "w", stdout);
    scanf("%d %d %d", &n, &m, &q);
    cnt = vi(1 << n, 0);
    w = vi(n, 0);
    FOR(i, 0, n) {
        scanf("%d", &w[n-i-1]);
    }
    st = vector<vii >(1 << n, vii(1 << n));
    sum = vvi(1 << n, vi(1 << n, 0));
    int x;
    FOR(i, 0, m) {
        scanf("%d", &x);
        x = bin2dec(x);
        cnt[x]++;
    }

    FOR(i, 0, 1<<n) {
        FOR(j, 0, 1 << n) {
            x = 0;
            FOR(k, 0, n) {
                if (((i >> k) & 1) == ((j >> k) & 1)) {
                    x += w[k];
                }
            }
            st[i][j] = {x, cnt[j]};
        }
        sort(st[i].begin(), st[i].end());
        sum[i][0] = st[i][0].second;
        // cerr << st[i][0].second << endl;
        FOR(j, 1, 1 << n) {
            sum[i][j] = st[i][j].second + sum[i][j-1];
        }
    }

    int y;
    FOR(i, 0, q) {
        scanf("%d %d", &x, &y);
        x = bin2dec(x);
        y++;
        vii::iterator it = lower_bound(st[x].begin(), st[x].end(), make_pair(y, 0)) - 1;
        int index = distance(st[x].begin(), it);
        // cerr << index << endl;
        cout << sum[x][index] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define endl '\n'
#define MOD 1000000007

using namespace std;
typedef long long int ll;

vector<vector<array<int, 2>>> vals(4100);

int Hash(string &s)
{
	int ret = 0;
	for (auto c : s)
	{
		ret <<= 1;
		if (c == '1') ++ret;
	}
	return ret;
}

int findpos(vector<array<int, 2>> &v, int k)
{
	if (v[0][0] > k) return 0;
	int l = 0, r = v.size(); --r;
	while (l < r)
	{
		int m = (l+r+1)/2;
		if (v[m][0] > k) r = m-1;
		else l = m;
	}
	return v[l][0] > k?v[l-1][1]:v[l][1];
}

int main(void)
{
	#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
	fast;
	int n, m, q; cin >> n >> m >> q;
	int w[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> w[i];
	}
	int lim = pow(2, n);
	int ct[lim]; memset(ct, 0, sizeof ct);
	int wu[lim]; memset(wu, 0, sizeof wu);
	for (int i = 0; i < m; ++i)
	{
		string s; cin >> s;
		int h = Hash(s);
		++ct[h];
	}
	for (int i = 0; i < lim; ++i)
	{
		int t = i;
		for (int k = n-1; k >= 0; --k)
		{
			if (!(t&1)) wu[i] += w[k];
			t >>= 1;
		}
	}
	for (int i = 0; i < lim; ++i)
	{
		for (int j = 0; j < lim; ++j)
		{
			if (!ct[j]) continue;
			int val = i^j;
			vals[i].pb({wu[val], ct[j]});
		}
		sort(vals[i].begin(), vals[i].end());
		int N = vals[i].size();
		for (int j = 1; j < N; ++j)
		{
			vals[i][j][1] += vals[i][j-1][1];
		}
	}
	while (q--)
	{
		string s; cin >> s; int h = Hash(s);
		int k; cin >> k;
		cout << findpos(vals[h], k) << '\n';
	}
}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define MOD 1000000007
#define MAX 10000000000
using namespace std;
typedef long long int ll;

vector<vector<pair<int, int>>> vals(5010);

int main(void){
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	#endif
	fast;
	int n, m, q; cin >> n >> m >> q;
	int w[n];
	for (int i = 0; i < n; ++i) {
		cin >> w[i];
	}
	vector<string> v(m);
	// unordered_map<string, int> M;
	set<int> M;
	int lim = pow(2, n);
	int ans[lim][120]; memset(ans, -1, sizeof ans);
	int co[lim]; memset(co, 0, sizeof co);
	for (int i = 0; i < m; ++i) {
		string x; cin >> x;
		int k = 0;
		for (int j = n-1; j >= 0; --j) {
			k *= 2;
			if (x[j] == '1')
				k += 1;
		}
		++co[k];
		if (co[k] == 1)
			M.insert(k);
	}
	for (int i = 0; i < lim; ++i) {
		string cur = "";
		int t = i;
		for (int j = 0; j < n; ++j) {
			if (t&1) cur += '1';
			else cur += '0';
			t >>= 1;
		}
		for (auto it : M) {
			string s = "";
			int temp = it;
			for (int j = 0; j < n; ++j) {
				if (temp&1) s += '1';
				else s += '0';
				temp >>= 1;
			}
			int val = 0;
			for (int j = 0; j < n; ++j) {
				if (cur[j] == s[j]) {
					val += w[j];
				}
			}
			vals[i].pb({val, co[it]});
		}
		sort(vals[i].begin(), vals[i].end());
		int N = vals[i].size();
		for (int j = 1; j < N; ++j) {
			vals[i][j].second += vals[i][j-1].second;
		}
	}
	// for (int i = 0; i < lim; ++i)
	// {
	// 	for (auto it : vals[i])
	// 		cout << it.second << ' ';
	// 	cout << '\n';
	// }
	while (q--) {
		string in; cin >> in;
		int k; cin >> k;
		int val = 0;
		for (int i = n-1; i >= 0; --i) {
			val *= 2;
			if (in[i] == '1')
				val += 1;
		}
		if (ans[val][k] != -1) {
			cout << ans[val][k] << '\n';
			continue;
		}
		if ((*vals[val].begin()).first > k) {
			ans[val][k] = 0;
			cout << 0 << '\n';
			continue;
		}
		pair<int, int> p = {k, 100000};
		auto it = upper_bound(vals[val].begin(), vals[val].end(), p);
		if (it == vals[val].end())
			--it;
		if (it->first > k)
			--it;
		ans[val][k] = it->second;
		cout << it->second << '\n';
	}

}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define endl '\n'
#define MOD 1000000007

using namespace std;
typedef long long int ll;

vector<vector<array<int, 2>>> vals(4100);
int ans[4100][101];

int Hash(string &s)
{
	int ret = 0;
	for (auto c : s)
	{
		ret <<= 1;
		if (c == '1') ++ret;
	}
	return ret;
}

int findpos(vector<array<int, 2>> &v, int k)
{
	if (v[0][0] > k) return 0;
	int l = 0, r = v.size(); --r;
	while (l < r)
	{
		int m = (l+r+1)/2;
		if (v[m][0] > k) r = m-1;
		else l = m;
	}
	return v[l][0] > k?v[l-1][1]:v[l][1];
}

int main(void)
{
	#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
	memset(ans, -1, sizeof ans);
	fast;
	int n, m, q; cin >> n >> m >> q;
	int w[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> w[i];
	}
	int lim = pow(2, n);
	int ct[lim]; memset(ct, 0, sizeof ct);
	int wu[lim]; memset(wu, 0, sizeof wu);
	for (int i = 0; i < m; ++i)
	{
		string s; cin >> s;
		int h = Hash(s);
		++ct[h];
	}
	for (int i = 0; i < lim; ++i)
	{
		int t = i;
		for (int k = n-1; k >= 0; --k)
		{
			if (!(t&1)) wu[i] += w[k];
			t >>= 1;
		}
	}
	for (int i = 0; i < lim; ++i)
	{
		for (int j = 0; j < lim; ++j)
		{
			if (!ct[j]) continue;
			vals[i].pb({wu[i^j], ct[j]});
		}
		sort(vals[i].begin(), vals[i].end());
		int N = vals[i].size();
		for (int j = 1; j < N; ++j)
		{
			vals[i][j][1] += vals[i][j-1][1];
		}
	}
	while (q--)
	{
		string s; cin >> s; int h = Hash(s);
		int k; cin >> k;
		if (ans[h][k] == -1) ans[h][k] = findpos(vals[h], k);
		cout << ans[h][k] << '\n';
	}
}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define endl '\n'
#define MOD 1000000007

using namespace std;
typedef long long int ll;

vector<vector<array<int, 2>>> vals(4100);

int Hash(string s)
{
	int ret = 0;
	for (auto c : s)
	{
		ret <<= 1;
		if (c == '1') ++ret;
	}
	return ret;
}

int findpos(vector<array<int, 2>> &v, int k)
{
	if (v[0][0] > k) return 0;
	int l = 0, r = v.size(); --r;
	while (l < r)
	{
		int m = (l+r+1)/2;
		if (v[m][0] > k) r = m-1;
		else l = m;
	}
	return v[l][0] > k?v[l-1][1]:v[l][1];
}

int main(void)
{
	#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
	fast;
	int n, m, q; cin >> n >> m >> q;
	int w[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> w[i];
	}
	int lim = pow(2, n);
	int ct[lim]; memset(ct, 0, sizeof ct);
	for (int i = 0; i < m; ++i)
	{
		string s; cin >> s;
		int h = Hash(s);
		++ct[h];
	}
	for (int i = 0; i < lim; ++i)
	{
		for (int j = 0; j < lim; ++j)
		{
			if (!ct[j]) continue;
			int val = i^j, wu = 0;
			for (int k = n-1; k >= 0; --k)
			{
				if (!(val&1)) wu += w[k];
				val >>= 1;
			}
			// cerr << i << ' ' << j << ' ' << wu << ' ' << ct[j] << endl;
			vals[i].pb({wu, ct[j]});
		}
		sort(vals[i].begin(), vals[i].end());
		int N = vals[i].size();
		for (int j = 1; j < N; ++j)
		{
			vals[i][j][1] += vals[i][j-1][1];
		}
	}
	while (q--)
	{
		string s; cin >> s; int h = Hash(s);
		// cerr << endl << h << "  "; for (auto it : vals[h]) cerr << "(" << it[0] << "," << it[1] << ")";
		int k; cin >> k;
		cout << findpos(vals[h], k) << endl;
	}
}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define endl '\n'
#define MOD 1000000007

using namespace std;
typedef long long int ll;

vector<array<int, 2>> vals[4100];

int Hash(string &s)
{
	int ret = 0;
	for (auto c : s)
	{
		ret <<= 1;
		if (c == '1') ++ret;
	}
	return ret;
}

int findpos(vector<array<int, 2>> &v, int k)
{
	if (v[0][0] > k) return 0;
	int l = 0, r = v.size(); --r;
	while (l < r)
	{
		int m = (l+r+1)/2;
		if (v[m][0] > k) r = m-1;
		else l = m;
	}
	return v[l][0] > k?v[l-1][1]:v[l][1];
}

int main(void)
{
	#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
	fast;
	int n, m, q; cin >> n >> m >> q;
	int w[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> w[i];
	}
	int lim = pow(2, n);
	int ct[lim]; memset(ct, 0, sizeof ct);
	int wu[lim]; memset(wu, 0, sizeof wu);
	for (int i = 0; i < m; ++i)
	{
		string s; cin >> s;
		int h = Hash(s);
		++ct[h];
	}
	for (int i = 0; i < lim; ++i)
	{
		int t = i;
		for (int k = n-1; k >= 0; --k)
		{
			if (!(t&1)) wu[i] += w[k];
			t >>= 1;
		}
	}
	for (int i = 0; i < lim; ++i)
	{
		for (int j = 0; j < lim; ++j)
		{
			if (!ct[j]) continue;
			int val = i^j;
			vals[i].pb({wu[val], ct[j]});
		}
		sort(vals[i].begin(), vals[i].end());
		int N = vals[i].size();
		for (int j = 1; j < N; ++j)
		{
			vals[i][j][1] += vals[i][j-1][1];
		}
	}
	while (q--)
	{
		string s; cin >> s; int h = Hash(s);
		int k; cin >> k;
		cout << findpos(vals[h], k) << '\n';
	}
}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define endl '\n'
#define MOD 1000000007

using namespace std;
typedef long long int ll;

vector<vector<array<int, 2>>> vals(4100);
int ans[4100][100];

int Hash(string &s)
{
	int ret = 0;
	for (auto c : s)
	{
		ret <<= 1;
		if (c == '1') ++ret;
	}
	return ret;
}

int findpos(vector<array<int, 2>> &v, int k)
{
	if (v[0][0] > k) return 0;
	int l = 0, r = v.size(); --r;
	while (l < r)
	{
		int m = (l+r+1)/2;
		if (v[m][0] > k) r = m-1;
		else l = m;
	}
	return v[l][0] > k?v[l-1][1]:v[l][1];
}

int main(void)
{
	#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
	memset(ans, -1, sizeof ans);
	fast;
	int n, m, q; cin >> n >> m >> q;
	int w[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> w[i];
	}
	int lim = pow(2, n);
	int ct[lim]; memset(ct, 0, sizeof ct);
	int wu[lim]; memset(wu, 0, sizeof wu);
	for (int i = 0; i < m; ++i)
	{
		string s; cin >> s;
		int h = Hash(s);
		++ct[h];
	}
	for (int i = 0; i < lim; ++i)
	{
		int t = i;
		for (int k = n-1; k >= 0; --k)
		{
			if (!(t&1)) wu[i] += w[k];
			t >>= 1;
		}
	}
	for (int i = 0; i < lim; ++i)
	{
		for (int j = 0; j < lim; ++j)
		{
			if (!ct[j]) continue;
			vals[i].pb({wu[i^j], ct[j]});
		}
		sort(vals[i].begin(), vals[i].end());
		int N = vals[i].size();
		for (int j = 1; j < N; ++j)
		{
			vals[i][j][1] += vals[i][j-1][1];
		}
	}
	while (q--)
	{
		string s; cin >> s; int h = Hash(s);
		int k; cin >> k;
		if (ans[h][k] == -1) ans[h][k] = findpos(vals[h], k);
		cout << ans[h][k] << '\n';
	}
}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define MOD 1000000007
#define MAX 10000000000
using namespace std;
typedef long long int ll;

vector<vector<pair<int, int>>> vals(5010);

int main(void){
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	#endif
	fast;
	int n, m, q; cin >> n >> m >> q;
	int w[n];
	for (int i = 0; i < n; ++i) {
		cin >> w[i];
	}
	vector<string> v(m);
	// unordered_map<string, int> M;
	set<int> M;
	int lim = pow(2, n);
	int ans[lim]; memset(ans, 0, sizeof ans);
	int co[lim]; memset(co, 0, sizeof co);
	for (int i = 0; i < m; ++i) {
		string x; cin >> x;
		int k = 0;
		for (int j = n-1; j >= 0; --j) {
			k *= 2;
			if (x[j] == '1')
				k += 1;
		}
		++co[k];
		if (co[k] == 1)
			M.insert(k);
	}
	for (int i = 0; i < lim; ++i) {
		string cur = "";
		int t = i;
		for (int j = 0; j < n; ++j) {
			if (t&1) cur += '1';
			else cur += '0';
			t >>= 1;
		}
		for (auto it : M) {
			string s = "";
			int temp = it;
			for (int j = 0; j < n; ++j) {
				if (temp&1) s += '1';
				else s += '0';
				temp >>= 1;
			}
			int val = 0;
			for (int j = 0; j < n; ++j) {
				if (cur[j] == s[j]) {
					val += w[j];
				}
			}
			vals[i].pb({val, co[it]});
		}
		sort(vals[i].begin(), vals[i].end());
		int N = vals[i].size();
		for (int j = 1; j < N; ++j) {
			vals[i][j].second += vals[i][j-1].second;
		}
	}
	// for (int i = 0; i < lim; ++i)
	// {
	// 	for (auto it : vals[i])
	// 		cout << it.second << ' ';
	// 	cout << '\n';
	// }
	while (q--) {
		string in; cin >> in;
		int k; cin >> k;
		int val = 0;
		for (int i = n-1; i >= 0; --i) {
			val *= 2;
			if (in[i] == '1')
				val += 1;
		}
		if ((*vals[val].begin()).first > k) {
			cout << 0 << '\n';
			continue;
		}
		pair<int, int> p = {k, 100000};
		auto it = upper_bound(vals[val].begin(), vals[val].end(), p);
		if (it == vals[val].end())
			--it;
		if (it->first > k)
			--it;
		cout << it->second << '\n';
	}

}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define endl '\n'
#define MOD 1000000007

using namespace std;
typedef long long int ll;

vector<vector<array<int, 2>>> vals(4100);

int Hash(string &s)
{
	int ret = 0;
	for (auto c : s)
	{
		ret <<= 1;
		if (c == '1') ++ret;
	}
	return ret;
}

int findpos(vector<array<int, 2>> &v, int k)
{
	if (v[0][0] > k) return 0;
	int l = 0, r = v.size(); --r;
	while (l < r)
	{
		int m = (l+r+1)/2;
		if (v[m][0] > k) r = m-1;
		else l = m;
	}
	return v[l][0] > k?v[l-1][1]:v[l][1];
}

int main(void)
{
	#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
	fast;
	int n, m, q; cin >> n >> m >> q;
	int w[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> w[i];
	}
	int lim = pow(2, n);
	int ct[lim]; memset(ct, 0, sizeof ct);
	for (int i = 0; i < m; ++i)
	{
		string s; cin >> s;
		int h = Hash(s);
		++ct[h];
	}
	for (int i = 0; i < lim; ++i)
	{
		for (int j = 0; j < lim; ++j)
		{
			if (!ct[j]) continue;
			int val = i^j, wu = 0;
			for (int k = n-1; k >= 0; --k)
			{
				if (!(val&1)) wu += w[k];
				val >>= 1;
			}
			vals[i].pb({wu, ct[j]});
		}
		sort(vals[i].begin(), vals[i].end());
		int N = vals[i].size();
		for (int j = 1; j < N; ++j)
		{
			vals[i][j][1] += vals[i][j-1][1];
		}
	}
	while (q--)
	{
		string s; cin >> s; int h = Hash(s);
		int k; cin >> k;
		cout << findpos(vals[h], k) << '\n';
	}
}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define endl '\n'
#define MOD 1000000007

using namespace std;
typedef long long int ll;

vector<vector<array<int, 2>>> vals(4100);

int Hash(string s)
{
	int ret = 0;
	for (auto c : s)
	{
		ret <<= 1;
		if (c == '1') ++ret;
	}
	return ret;
}

int findpos(vector<array<int, 2>> &v, int k)
{
	if (v[0][0] > k) return 0;
	int l = 0, r = v.size(); --r;
	while (l < r)
	{
		int m = (l+r+1)/2;
		if (v[m][0] > k) r = m-1;
		else l = m;
	}
	return v[l][0] > k?v[l-1][1]:v[l][1];
}

int main(void)
{
	#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
	fast;
	int n, m, q; cin >> n >> m >> q;
	int w[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> w[i];
	}
	int lim = pow(2, n);
	int ct[lim]; memset(ct, 0, sizeof ct);
	for (int i = 0; i < m; ++i)
	{
		string s; cin >> s;
		int h = Hash(s);
		++ct[h];
	}
	for (int i = 0; i < lim; ++i)
	{
		for (int j = 0; j < lim; ++j)
		{
			if (!ct[j]) continue;
			int val = i^j, wu = 0;
			for (int k = n-1; k >= 0; --k)
			{
				if (!(val&1)) wu += w[k];
				val >>= 1;
			}
			// cerr << i << ' ' << j << ' ' << wu << ' ' << ct[j] << endl;
			vals[i].pb({wu, ct[j]});
		}
		sort(vals[i].begin(), vals[i].end());
		int N = vals[i].size();
		for (int j = 1; j < N; ++j)
		{
			vals[i][j][1] += vals[i][j-1][1];
		}
	}
	int ans[lim]; memset(ans, -1, sizeof ans);
	while (q--)
	{
		string s; cin >> s; int h = Hash(s);
		if (ans[h] != -1)
		{
			cout << ans[h] << '\n';
			continue;
		}
		// cerr << endl << h << "  "; for (auto it : vals[h]) cerr << "(" << it[0] << "," << it[1] << ")";
		int k; cin >> k;
		ans[h] = findpos(vals[h], k);
		cout << ans[h] << endl;
	}
}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define MOD 1000000007
#define MAX 10000000000
using namespace std;
typedef long long int ll;

vector<vector<pair<int, int>>> vals(5010);

int main(void){
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	#endif
	fast;
	int n, m, q; cin >> n >> m >> q;
	int w[n];
	for (int i = 0; i < n; ++i) {
		cin >> w[i];
	}
	vector<string> v(m);
	unordered_map<string, int> M;
	for (int i = 0; i < m; ++i) {
		string x; cin >> x;
		++M[x];
	}
	int lim = pow(2, n);
	int ans[lim]; memset(ans, 0, sizeof ans);
	for (int i = 0; i < lim; ++i) {
		string cur = "";
		int t = i;
		for (int j = 0; j < n; ++j) {
			if (t&1) cur += '1';
			else cur += '0';
		}
		for (auto it : M) {
			int val = 0;
			for (int j = 0; j < n; ++j) {
				if (cur[j] == it.first[j]) {
					val += w[j];
				}
			}
			vals[i].pb({val, it.second});
		}
		sort(vals[i].begin(), vals[i].end());
		int N = vals[i].size();
		for (int j = 1; j < N; ++j) {
			vals[i][j].second += vals[i][j-1].second;
		}
	}
	// for (int i = 0; i < lim; ++i)
	// {
	// 	for (auto it : vals[i])
	// 		cout << it.second << ' ';
	// 	cout << '\n';
	// }
	while (q--) {
		string in; cin >> in;
		int k; cin >> k;
		int val = 0;
		for (int i = n-1; i >= 0; --i) {
			val *= 2;
			if (in[i] == '1')
				val += 1;
		}
		if ((*vals[val].begin()).first > k) {
			cout << 0 << '\n';
			continue;
		}
		pair<int, int> p = {k, 100000};
		auto it = upper_bound(vals[val].begin(), vals[val].end(), p);
		if (it == vals[val].end())
			--it;
		if (it->first > k)
			--it;
		cout << it->second << '\n';
	}

}


#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define MOD 1000000007
#define MAX 10000000000
using namespace std;
typedef long long int ll;

vector<vector<pair<int, int>>> vals(5010);

int main(void){
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	#endif
	fast;
	int n, m, q; cin >> n >> m >> q;
	int w[n];
	for (int i = 0; i < n; ++i) {
		cin >> w[i];
	}
	vector<string> v(m);
	map<string, int> M;
	for (int i = 0; i < m; ++i) {
		cin >> v[i];
		++M[v[i]];
	}
	int lim = pow(2, n);
	int ans[lim]; memset(ans, 0, sizeof ans);
	for (int i = 0; i < lim; ++i) {
		string cur = "";
		int t = i;
		for (int j = 0; j < n; ++j) {
			if (t&1) cur += '1';
			else cur += '0';
		}
		for (auto it : M) {
			int val = 0;
			for (int j = 0; j < n; ++j) {
				if (cur[j] == it.first[j]) {
					val += w[j];
				}
			}
			vals[i].pb({val, it.second});
		}
		sort(vals[i].begin(), vals[i].end());
		int N = vals[i].size();
		for (int j = 1; j < N; ++j) {
			vals[i][j].second += vals[i][j-1].second;
		}
	}
	// for (int i = 0; i < lim; ++i)
	// {
	// 	for (auto it : vals[i])
	// 		cout << it.second << ' ';
	// 	cout << '\n';
	// }
	while (q--) {
		string in; cin >> in;
		int k; cin >> k;
		int val = 0;
		for (int i = n-1; i >= 0; --i) {
			val *= 2;
			if (in[i] == '1')
				val += 1;
		}
		if ((*vals[val].begin()).first > k) {
			cout << 0 << '\n';
			continue;
		}
		pair<int, int> p = {k, 100000};
		auto it = upper_bound(vals[val].begin(), vals[val].end(), p);
		if (it == vals[val].end())
			--it;
		if (it->first > k)
			--it;
		cout << it->second << '\n';
	}

}


#include <iostream>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define forr(i,a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(int i = int(a); i > int(b); --i)
#define rforn(i,n) rforr(i,n,0)
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;

//~ struct chash {
    //~ int operator()(pii x) const { return x.first* 31 + x.second; }
//~ };
//~ gp_hash_table<pii, int, chash> ANS;

const int MAXN = 1<<12;
const int MAXQ = 500005;

struct query{
	int k, ans;
	vector <int> ind;
	bool operator < (const query &o) const{
		return k < o.k;
	}
	bool operator == (const query &o) const{
		return k == o.k;
	}
};

int N, M, K;
vector <int> W;
pii Q[MAXQ];
set <int> S[MAXN];
vector <int> V[MAXN];
int WU[MAXN];
int SET[MAXN];
char s[16];
int ANS[MAXN][100];

int sToInt(){
	int ans = 0;
	forn(i, N)
		if(s[i] == '1')
			ans |= (1<<i);
	return ans;
}

inline void fillWu(){
	forn(i, (1<<N)){
		int wu = 0;
		forn(j, N)
			if(i & (1<<j))
				wu += W[j];
		WU[i] = wu;
	}
}

int main(){
	//~ ios::sync_with_stdio(false);
	//~ cin.tie(NULL);
	//~ freopen("input.in", "r", stdin);
	scanf("%d %d %d", &N, &M, &K);

	int aux;
	forn(i, N){
		scanf("%d", &aux);
		W.push_back(aux);
	}

	fillWu();

	forn(m, M){
		scanf(" %s", s);
		SET[ sToInt() ]++;
	}

	int k;
	forn(ind, K){
		scanf(" %s %d", s, &k);
		aux = sToInt();
		pii auxp = {aux, k};
		Q[ind] = auxp;
		if(S[aux].count(k) == 0)
			S[aux].insert(k);
	}

	int cadenas = 1<<N;
	int mask = 0;
	forn(i, N)
		mask |= (1<<i);

	forn(i, cadenas)
		for(auto &k: S[i])
			V[i].push_back(k);

	forn(i, cadenas)
		forn(j, cadenas){
			int cost = WU[mask & (~(i^j))];
			//printf("estoy comparando %d y %d, da %d tienen wu %hd\n", i, j, mask & (~(i^j)), cost);
			for(auto &k : V[i])
				if(cost <= k)
					//printf("la query de %d que pide costo %d anda y le estoy sumando %d que es la cantidad de %d\n", i, k, SET[j], j);
					ANS[i][k] += SET[j];
		}

	forn(i, K)
		printf("%d\n", ANS[ Q[i].first ][ Q[i].second ]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("sse, sse2, sse3, ssse3, sse4, popcnt, abm, mmx, abx, tune=native")
#define forr(i,a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(int i = int(a); i > int(b); --i)
#define rforn(i,n) rforr(i,n,0)

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned short int sint;

using namespace std;

const int MAXN = 1<<12;
const int MAXQ = 500001;

struct query{
	int k, ind;
};

int N, M, K;
vector <sint> W;
vector <query> Q[MAXN];
sint WU[MAXN];
int SET[MAXN];
int ANS[MAXQ];
char s[16];

sint sToShort(){
	sint ans = 0;
	forn(i, N)
		if(s[i] == '1')
			ans |= (1<<i);
	return ans;
}

inline void fillWu(){
	forn(i, (1<<N)){
		sint wu = 0;
		forn(j, N)
			if(i & (1<<j))
				wu += W[j];
		WU[i] = wu;
	}
}

int main(){
	//~ ios::sync_with_stdio(false);
	//~ cin.tie(NULL);
	//~ freopen("input.in", "r", stdin);
	scanf("%d %d %d", &N, &M, &K);

	sint aux;
	forn(i, N){
		scanf("%hd", &aux);
		W.push_back(aux);
	}

	fillWu();

	forn(m, M){
		scanf(" %s", s);
		SET[ sToShort() ]++;
	}

	sint k;
	forn(ind, K){
		scanf(" %s %hd", s, &k);
		aux = sToShort();
		Q[aux].push_back({k, ind});
	}

	int cadenas = 1<<N;
	int mask = 0;
	forn(i, N)
		mask |= (1<<i);

	forn(i, cadenas)
		forn(j, cadenas){
			sint cost = WU[mask & (~(i^j))];
			//~ printf("estoy comparando %d y %d, da %d tienen wu %hd\n", i, j, mask & (~(i^j)), cost);
			for(auto &q : Q[i])
				if(cost <= q.k){
					//~ printf("la query %d que pide costo %d anda y le estoy sumando %d que es la cantidad de %d\n", q.ind+1, q.k, SET[j], j);
					ANS[q.ind] += SET[j];
				}
		}

	forn(i, K)
		printf("%d\n", ANS[i]);
	return 0;
}


#include <iostream>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("sse, sse2, sse3, ssse3, sse4, popcnt, abm, mmx, abx, tune=native")
#define forr(i,a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(int i = int(a); i > int(b); --i)
#define rforn(i,n) rforr(i,n,0)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 1<<12;
const int MAXQ = 500001;

struct query{
	int k, ans;
	vector <int> ind;
	bool operator < (const query &o) const{
		return k < o.k;
	}
	bool operator == (const query &o) const{
		return k == o.k;
	}
};

map <pii, int> ANS;

int N, M, K;
vector <int> W;
pii Q[MAXN];
set <int> S[MAXN];
int mapIndex = 0;

int WU[MAXN];
int SET[MAXN];
char s[16];

int sToInt(){
	int ans = 0;
	forn(i, N)
		if(s[i] == '1')
			ans |= (1<<i);
	return ans;
}

inline void fillWu(){
	forn(i, (1<<N)){
		int wu = 0;
		forn(j, N)
			if(i & (1<<j))
				wu += W[j];
		WU[i] = wu;
	}
}

int main(){
	//~ ios::sync_with_stdio(false);
	//~ cin.tie(NULL);
	//~ freopen("input.in", "r", stdin);
	scanf("%d %d %d", &N, &M, &K);

	int aux;
	forn(i, N){
		scanf("%d", &aux);
		W.push_back(aux);
	}

	fillWu();

	forn(m, M){
		scanf(" %s", s);
		SET[ sToInt() ]++;
	}

	int k;
	forn(ind, K){
		scanf(" %s %d", s, &k);
		aux = sToInt();
		pii auxp = {aux, k};
		Q[ind] = auxp;
		if(S[aux].count(k) == 0){
			S[aux].insert(k);
			ANS[auxp] = 0;
		}
	}

	int cadenas = 1<<N;
	int mask = 0;
	forn(i, N)
		mask |= (1<<i);

	forn(i, cadenas)
		forn(j, cadenas){
			int cost = WU[mask & (~(i^j))];
			//~ printf("estoy comparando %d y %d, da %d tienen wu %hd\n", i, j, mask & (~(i^j)), cost);
			for(auto &k : S[i])
				if(cost <= k){
					//~ printf("la query %d que pide costo %d anda y le estoy sumando %d que es la cantidad de %d\n", q.ind+1, q.k, SET[j], j);
					ANS[{i, k}] += SET[j];
				}
		}

	forn(i, K)
		printf("%d\n", ANS[ Q[i] ]);
	return 0;
}


#include <iostream>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define forr(i,a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(int i = int(a); i > int(b); --i)
#define rforn(i,n) rforr(i,n,0)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 1<<12;
const int MAXQ = 500005;

struct query{
	int k, ans;
	vector <int> ind;
	bool operator < (const query &o) const{
		return k < o.k;
	}
	bool operator == (const query &o) const{
		return k == o.k;
	}
};

int N, M, K;
vector <int> W;
pii Q[MAXQ];
set <int> S[MAXN];
vector <int> V[MAXN];
int WU[MAXN];
int SET[MAXN];
char s[16];
int ANS[MAXQ][101];

int sToInt(){
	int ans = 0;
	forn(i, N)
		if(s[i] == '1')
			ans |= (1<<i);
	return ans;
}

inline void fillWu(){
	forn(i, (1<<N)){
		int wu = 0;
		forn(j, N)
			if(i & (1<<j))
				wu += W[j];
		WU[i] = wu;
	}
}

int main(){
	//~ ios::sync_with_stdio(false);
	//~ cin.tie(NULL);
	//~ freopen("input.in", "r", stdin);
	scanf("%d %d %d", &N, &M, &K);

	int aux;
	forn(i, N){
		scanf("%d", &aux);
		W.push_back(aux);
	}

	fillWu();

	forn(m, M){
		scanf(" %s", s);
		SET[ sToInt() ]++;
	}

	int k;
	forn(ind, K){
		scanf(" %s %d", s, &k);
		aux = sToInt();
		pii auxp = {aux, k};
		Q[ind] = auxp;
		if(S[aux].count(k) == 0)
			S[aux].insert(k);
	}

	int cadenas = 1<<N;
	int mask = 0;
	forn(i, N)
		mask |= (1<<i);

	forn(i, cadenas)
		for(auto &k: S[i])
			V[i].push_back(k);

	forn(i, cadenas)
		forn(j, cadenas){
			int cost = WU[mask & (~(i^j))];
			//~ printf("estoy comparando %d y %d, da %d tienen wu %hd\n", i, j, mask & (~(i^j)), cost);
			for(auto &k : V[i])
				if(cost <= k){
					//~ printf("la query de %d que pide costo %d anda y le estoy sumando %d que es la cantidad de %d\n", i, k, SET[j], j);
					ANS[i][k] += SET[j];
				}
		}

	forn(i, K)
		printf("%d\n", ANS[ Q[i].first ][ Q[i].second ]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#define forr(i,a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(int i = int(a); i > int(b); --i)
#define rforn(i,n) rforr(i,n,0)

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned short int sint;

using namespace std;

const int MAXN = 1<<12;
const int MAXQ = 500001;

struct query{
	int k, ind;
};

int N, M, K;
vector <sint> W;
vector <query> Q[MAXN];
sint WU[MAXN];
int SET[MAXN];
int ANS[MAXQ];
char s[16];

sint sToShort(){
	sint ans = 0;
	forn(i, N)
		if(s[i] == '1')
			ans |= (1<<i);
	return ans;
}

inline void fillWu(){
	forn(i, (1<<N)){
		sint wu = 0;
		forn(j, N)
			if(i & (1<<j))
				wu += W[j];
		WU[i] = wu;
	}
}

int main(){
	//~ ios::sync_with_stdio(false);
	//~ cin.tie(NULL);
	freopen("input.in", "r", stdin);
	scanf("%d %d %d", &N, &M, &K);

	sint aux;
	forn(i, N){
		scanf("%hd", &aux);
		W.push_back(aux);
	}

	fillWu();

	forn(m, M){
		scanf(" %s", s);
		SET[ sToShort() ]++;
	}

	sint k;
	forn(ind, K){
		scanf(" %s %hd", s, &k);
		aux = sToShort();
		Q[aux].push_back({k, ind});
	}

	int cadenas = 1<<N;
	int mask = 0;
	forn(i, N)
		mask |= (1<<i);

	forn(i, cadenas)
		forn(j, cadenas){
			sint cost = WU[mask & (~(i^j))];
			//~ printf("estoy comparando %d y %d, da %d tienen wu %hd\n", i, j, mask & (~(i^j)), cost);
			for(auto &q : Q[i])
				if(cost <= q.k){
					//~ printf("la query %d que pide costo %d anda y le estoy sumando %d que es la cantidad de %d\n", q.ind+1, q.k, SET[j], j);
					ANS[q.ind] += SET[j];
				}
		}

	forn(i, K)
		printf("%d\n", ANS[i]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#define forr(i,a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(int i = int(a); i > int(b); --i)
#define rforn(i,n) rforr(i,n,0)

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned short int sint;

using namespace std;

const int MAXN = 1<<12;
const int MAXQ = 500001;

struct query{
	int k, ind;
};

int N, M, K;
vector <sint> W;
vector <query> Q[MAXN];
sint WU[MAXN];
int SET[MAXN];
int ANS[MAXQ];
char s[16];

sint sToShort(){
	sint ans = 0;
	forn(i, N)
		if(s[i] == '1')
			ans |= (1<<i);
	return ans;
}

inline void fillWu(){
	forn(i, (1<<N)){
		sint wu = 0;
		forn(j, N)
			if(i & (1<<j))
				wu += W[j];
		WU[i] = wu;
	}
}

int main(){
	//~ ios::sync_with_stdio(false);
	//~ cin.tie(NULL);
	//~ freopen("input.in", "r", stdin);
	scanf("%d %d %d", &N, &M, &K);

	sint aux;
	forn(i, N){
		scanf("%hd", &aux);
		W.push_back(aux);
	}

	fillWu();

	forn(m, M){
		scanf(" %s", s);
		SET[ sToShort() ]++;
	}

	sint k;
	forn(ind, K){
		scanf(" %s %hd", s, &k);
		aux = sToShort();
		Q[aux].push_back({k, ind});
	}

	int cadenas = 1<<N;
	int mask = 0;
	forn(i, N)
		mask |= (1<<i);

	forn(i, cadenas)
		forn(j, cadenas){
			sint cost = WU[mask & (~(i^j))];
			//~ printf("estoy comparando %d y %d, da %d tienen wu %hd\n", i, j, mask & (~(i^j)), cost);
			for(auto &q : Q[i])
				if(cost <= q.k){
					//~ printf("la query %d que pide costo %d anda y le estoy sumando %d que es la cantidad de %d\n", q.ind+1, q.k, SET[j], j);
					ANS[q.ind] += SET[j];
				}
		}

	forn(i, K)
		printf("%d\n", ANS[i]);
	return 0;
}


#include <iostream>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#define forr(i,a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(int i = int(a); i > int(b); --i)
#define rforn(i,n) rforr(i,n,0)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 1<<12;
const int MAXQ = 500005;

struct query{
	int k, ans;
	vector <int> ind;
	bool operator < (const query &o) const{
		return k < o.k;
	}
	bool operator == (const query &o) const{
		return k == o.k;
	}
};

int N, M, K;
vector <int> W;
pii Q[MAXQ];
set <int> S[MAXN];
vector <int> V[MAXN];
int WU[MAXN];
int SET[MAXN];
char s[16];
int ANS[MAXQ][101];

int sToInt(){
	int ans = 0;
	forn(i, N)
		if(s[i] == '1')
			ans |= (1<<i);
	return ans;
}

inline void fillWu(){
	forn(i, (1<<N)){
		int wu = 0;
		forn(j, N)
			if(i & (1<<j))
				wu += W[j];
		WU[i] = wu;
	}
}

int main(){
	//~ ios::sync_with_stdio(false);
	//~ cin.tie(NULL);
	//~ freopen("input.in", "r", stdin);
	scanf("%d %d %d", &N, &M, &K);

	int aux;
	forn(i, N){
		scanf("%d", &aux);
		W.push_back(aux);
	}

	fillWu();

	forn(m, M){
		scanf(" %s", s);
		SET[ sToInt() ]++;
	}

	int k;
	forn(ind, K){
		scanf(" %s %d", s, &k);
		aux = sToInt();
		pii auxp = {aux, k};
		Q[ind] = auxp;
		if(S[aux].count(k) == 0)
			S[aux].insert(k);
	}

	int cadenas = 1<<N;
	int mask = 0;
	forn(i, N)
		mask |= (1<<i);

	forn(i, cadenas)
		for(auto &k: S[i])
			V[i].push_back(k);

	forn(i, cadenas)
		forn(j, cadenas){
			int cost = WU[mask & (~(i^j))];
			//~ printf("estoy comparando %d y %d, da %d tienen wu %hd\n", i, j, mask & (~(i^j)), cost);
			for(auto &k : V[i])
				if(cost <= k){
					//~ printf("la query de %d que pide costo %d anda y le estoy sumando %d que es la cantidad de %d\n", i, k, SET[j], j);
					ANS[i][k] += SET[j];
				}
		}

	forn(i, K)
		printf("%d\n", ANS[ Q[i].first ][ Q[i].second ]);
	return 0;
}


#include <iostream>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("sse, sse2, sse3, ssse3, sse4, popcnt, abm, mmx, abx, tune=native")
#define forr(i,a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(int i = int(a); i > int(b); --i)
#define rforn(i,n) rforr(i,n,0)
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;

struct chash {
    int operator()(pii x) const { return x.first* 31 + x.second; }
};
gp_hash_table<pii, int, chash> ANS;

const int MAXN = 1<<12;
const int MAXQ = 500005;

struct query{
	int k, ans;
	vector <int> ind;
	bool operator < (const query &o) const{
		return k < o.k;
	}
	bool operator == (const query &o) const{
		return k == o.k;
	}
};

int N, M, K;
vector <int> W;
pii Q[MAXQ];
set <int> S[MAXN];
vector <int> V[MAXN];
int WU[MAXN];
int SET[MAXN];
char s[16];

int sToInt(){
	int ans = 0;
	forn(i, N)
		if(s[i] == '1')
			ans |= (1<<i);
	return ans;
}

inline void fillWu(){
	forn(i, (1<<N)){
		int wu = 0;
		forn(j, N)
			if(i & (1<<j))
				wu += W[j];
		WU[i] = wu;
	}
}

int main(){
	//~ ios::sync_with_stdio(false);
	//~ cin.tie(NULL);
	//~ freopen("input.in", "r", stdin);
	scanf("%d %d %d", &N, &M, &K);

	int aux;
	forn(i, N){
		scanf("%d", &aux);
		W.push_back(aux);
	}

	fillWu();

	forn(m, M){
		scanf(" %s", s);
		SET[ sToInt() ]++;
	}

	int k;
	forn(ind, K){
		scanf(" %s %d", s, &k);
		aux = sToInt();
		pii auxp = {aux, k};
		Q[ind] = auxp;
		if(S[aux].count(k) == 0){
			S[aux].insert(k);
			ANS[auxp] = 0;
		}
	}

	int cadenas = 1<<N;
	int mask = 0;
	forn(i, N)
		mask |= (1<<i);

	forn(i, cadenas)
		for(auto &k: S[i])
			V[i].push_back(k);

	forn(i, cadenas)
		forn(j, cadenas){
			int cost = WU[mask & (~(i^j))];
			//printf("estoy comparando %d y %d, da %d tienen wu %hd\n", i, j, mask & (~(i^j)), cost);
			for(auto &k : V[i])
				if(cost <= k){
					//printf("la query de %d que pide costo %d anda y le estoy sumando %d que es la cantidad de %d\n", i, k, SET[j], j);
					ANS[{i, k}] += SET[j];
				}
		}

	forn(i, K)
		printf("%d\n", ANS[ Q[i] ]);
	return 0;
}


#include <iostream>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("sse, sse2, sse3, ssse3, sse4, popcnt, abm, mmx, abx, tune=native")
#define forr(i,a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(int i = int(a); i > int(b); --i)
#define rforn(i,n) rforr(i,n,0)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 1<<12;
const int MAXQ = 500005;

struct query{
	int k, ans;
	vector <int> ind;
	bool operator < (const query &o) const{
		return k < o.k;
	}
	bool operator == (const query &o) const{
		return k == o.k;
	}
};

map <pii, int> ANS;

int N, M, K;
vector <int> W;
pii Q[MAXQ];
set <int> S[MAXN];
int WU[MAXN];
int SET[MAXN];
char s[16];

int sToInt(){
	int ans = 0;
	forn(i, N)
		if(s[i] == '1')
			ans |= (1<<i);
	return ans;
}

inline void fillWu(){
	forn(i, (1<<N)){
		int wu = 0;
		forn(j, N)
			if(i & (1<<j))
				wu += W[j];
		WU[i] = wu;
	}
}

int main(){
	//~ ios::sync_with_stdio(false);
	//~ cin.tie(NULL);
	//~ freopen("input.in", "r", stdin);
	scanf("%d %d %d", &N, &M, &K);

	int aux;
	forn(i, N){
		scanf("%d", &aux);
		W.push_back(aux);
	}

	fillWu();

	forn(m, M){
		scanf(" %s", s);
		SET[ sToInt() ]++;
	}

	int k;
	forn(ind, K){
		scanf(" %s %d", s, &k);
		aux = sToInt();
		pii auxp = {aux, k};
		Q[ind] = auxp;
		if(S[aux].count(k) == 0){
			S[aux].insert(k);
			ANS[auxp] = 0;
		}
	}

	int cadenas = 1<<N;
	int mask = 0;
	forn(i, N)
		mask |= (1<<i);

	forn(i, cadenas)
		forn(j, cadenas){
			int cost = WU[mask & (~(i^j))];
			//printf("estoy comparando %d y %d, da %d tienen wu %hd\n", i, j, mask & (~(i^j)), cost);
			for(auto &k : S[i])
				if(cost <= k){
					//printf("la query de %d que pide costo %d anda y le estoy sumando %d que es la cantidad de %d\n", i, k, SET[j], j);
					ANS[{i, k}] += SET[j];
				}
		}

	forn(i, K)
		printf("%d\n", ANS[ Q[i] ]);
	return 0;
}


#include <iostream>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("sse, sse2, sse3, ssse3, sse4, popcnt, abm, mmx, abx, tune=native")
#define forr(i,a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(int i = int(a); i > int(b); --i)
#define rforn(i,n) rforr(i,n,0)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 1<<12;
const int MAXQ = 500005;

struct query{
	int k, ans;
	vector <int> ind;
	bool operator < (const query &o) const{
		return k < o.k;
	}
	bool operator == (const query &o) const{
		return k == o.k;
	}
};

map <pii, int> ANS;

int N, M, K;
vector <int> W;
pii Q[MAXQ];
set <int> S[MAXN];
vector <int> V[MAXN];
int WU[MAXN];
int SET[MAXN];
char s[16];

int sToInt(){
	int ans = 0;
	forn(i, N)
		if(s[i] == '1')
			ans |= (1<<i);
	return ans;
}

inline void fillWu(){
	forn(i, (1<<N)){
		int wu = 0;
		forn(j, N)
			if(i & (1<<j))
				wu += W[j];
		WU[i] = wu;
	}
}

int main(){
	//~ ios::sync_with_stdio(false);
	//~ cin.tie(NULL);
	//~ freopen("input.in", "r", stdin);
	scanf("%d %d %d", &N, &M, &K);

	int aux;
	forn(i, N){
		scanf("%d", &aux);
		W.push_back(aux);
	}

	fillWu();

	forn(m, M){
		scanf(" %s", s);
		SET[ sToInt() ]++;
	}

	int k;
	forn(ind, K){
		scanf(" %s %d", s, &k);
		aux = sToInt();
		pii auxp = {aux, k};
		Q[ind] = auxp;
		if(S[aux].count(k) == 0){
			S[aux].insert(k);
			ANS[auxp] = 0;
		}
	}

	int cadenas = 1<<N;
	int mask = 0;
	forn(i, N)
		mask |= (1<<i);

	forn(i, cadenas)
		for(auto &k: S[i])
			V[i].push_back(k);

	forn(i, cadenas)
		forn(j, cadenas){
			int cost = WU[mask & (~(i^j))];
			//printf("estoy comparando %d y %d, da %d tienen wu %hd\n", i, j, mask & (~(i^j)), cost);
			for(auto &k : V[i])
				if(cost <= k){
					//printf("la query de %d que pide costo %d anda y le estoy sumando %d que es la cantidad de %d\n", i, k, SET[j], j);
					ANS[{i, k}] += SET[j];
				}
		}

	forn(i, K)
		printf("%d\n", ANS[ Q[i] ]);
	return 0;
}


#include <iostream>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("sse, sse2, sse3, ssse3, sse4, popcnt, abm, mmx, abx, tune=native")
#define forr(i,a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(int i = int(a); i > int(b); --i)
#define rforn(i,n) rforr(i,n,0)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 1<<12;
const int MAXQ = 500005;

struct query{
	int k, ans;
	vector <int> ind;
	bool operator < (const query &o) const{
		return k < o.k;
	}
	bool operator == (const query &o) const{
		return k == o.k;
	}
};

map <pii, int> ANS;

int N, M, K;
vector <int> W;
pii Q[MAXN];
set <int> S[MAXN];
int mapIndex = 0;

int WU[MAXN];
int SET[MAXN];
char s[16];

int sToInt(){
	int ans = 0;
	forn(i, N)
		if(s[i] == '1')
			ans |= (1<<i);
	return ans;
}

inline void fillWu(){
	forn(i, (1<<N)){
		int wu = 0;
		forn(j, N)
			if(i & (1<<j))
				wu += W[j];
		WU[i] = wu;
	}
}

int main(){
	//~ ios::sync_with_stdio(false);
	//~ cin.tie(NULL);
	//~ freopen("input.in", "r", stdin);
	scanf("%d %d %d", &N, &M, &K);

	int aux;
	forn(i, N){
		scanf("%d", &aux);
		W.push_back(aux);
	}

	fillWu();

	forn(m, M){
		scanf(" %s", s);
		SET[ sToInt() ]++;
	}

	int k;

	int noentiendonada = K;

	forn(ind, K){
		scanf(" %s %d", s, &k);
		aux = sToInt();
		pii auxp = {aux, k};
		Q[ind] = auxp;
		if(S[aux].count(k) == 0){
			S[aux].insert(k);
			ANS[auxp] = 0;
		}
	}

	K = noentiendonada;

	int cadenas = 1<<N;
	int mask = 0;
	forn(i, N)
		mask |= (1<<i);

	forn(i, cadenas)
		forn(j, cadenas){
			int cost = WU[mask & (~(i^j))];
			//~ printf("estoy comparando %d y %d, da %d tienen wu %hd\n", i, j, mask & (~(i^j)), cost);
			for(auto &k : S[i])
				if(cost <= k){
					//~ printf("la query %d que pide costo %d anda y le estoy sumando %d que es la cantidad de %d\n", q.ind+1, q.k, SET[j], j);
					ANS[{i, k}] += SET[j];
				}
		}

	forn(i, K)
		printf("%d\n", ANS[ Q[i] ]);
	return 0;
}


/*
 *
 * Author : fcbruce <fcbruce8964@gmail.com>
 *
 * Time : Wed 08 Aug 2018 22:53:27
 *
 */
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif

const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const double PI = acos(-1.0);
const double eps = 1e-10;

typedef long long LL;
typedef int itn;

const int maxn = 500007;
const int maxm = 0;

char buffer[16];

int n, m, q;
int w[16];

int s[maxn];

long long results[maxn];

inline int read_binary()
{
  scanf("%s", buffer);
  int v = 0;
  for (int i = 0; i < n; i++)
  {
    v = (v << 1) | (buffer[i] - '0');
  }
  return v;
}

struct Query
{
  int id;
  int s;
  int k;

  void read(int id)
  {
    this->id = id;
    s = read_binary();
    scanf("%d", &k);
  }

  bool operator <(const Query &rhs) const
  {
    return k < rhs.k;
  }

}query[maxn];

//std::map<int, int> smap;
int smap[8192];
std::vector<Query> qmap[8192];
//std::map<int, std::vector<Query>> qmap;

int qs[maxn];
int qsn;
int sn;

inline void read()
{
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < n; i++) scanf("%d", w + i);

  for (int i = 0; i < m; i++) s[i] = read_binary();

  for (int i = 0; i < q; i++) query[i].read(i);

}

inline void init()
{
  memset(smap, 0, sizeof smap);

  for (int i = 0; i < m; i++)
  {
    smap[s[i]]++;
  }

  for (int i = 0; i < q; i++)
  {
    qmap[query[i].s].push_back(query[i]);
    qs[i] = query[i].s;
  }

  std::sort(qs, qs + q);
  qsn = std::unique(qs, qs + q) - qs;

  std::sort(s, s + m);
  sn = std::unique(s, s + m) - s;

  //for (auto &e : qmap)
  for (int qi = 0; qi < qsn; qi++)
  {
    auto &v = qmap[qs[qi]];
    std::sort(v.begin(), v.end());
  }
}

inline int ith_bit(int s, int i)
{
  return s & (1 << (n - i - 1));
}

inline int calc_wu(int s, int t)
{
  int wu = 0;
  for (int i = 0; i < n; i++)
  {
    if (ith_bit(s, i) == ith_bit(t, i))
    {
      wu += w[i];
    }
  }
  return wu;
}

void solve()
{
  //for (auto &e: qmap)
  for (int qi = 0; qi < qsn; qi++)
  {
    int t = qs[qi];
    auto &v = qmap[t];
    //printf("gao %d\n", t);
    std::vector<std::pair<int, int>> wus;
    wus.reserve(4096);
    //for (auto &se : smap)
    for (int si = 0; si < sn; si++)
    {
      int s = ::s[si];
      int cnt = smap[s];
      int wu = calc_wu(s, t);
      wus.push_back(std::make_pair(wu, cnt));
      //printf("s = %d, wu = %d, cnt = %d\n", s, wu, cnt);
    }
    std::sort(wus.begin(), wus.end());
    // stat
    long long sum_wu = 0;
    for (int i = 0, j = 0; i < v.size() && j < wus.size(); i++)
    {
      Query &q = v[i];
      while (j < wus.size() && wus[j].first <= q.k)
      {
        sum_wu += wus[j].second;
        j++;
      }
      results[q.id] = sum_wu;
    }
    //puts("----");
  }
}

inline void print()
{
  for (int i = 0; i < q; i++) printf(lld "\n", results[i]);
}

int main()
{
#ifdef FCBRUCE
  freopen("/Users/fcbruce/code/acm/t", "r", stdin);
#endif // FCBRUCE

  read();

  init();

  solve();

  print();

  return 0;
}


/*
 *
 * Author : fcbruce <fcbruce8964@gmail.com>
 *
 * Time : Wed 08 Aug 2018 22:53:27
 *
 */
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif

const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const double PI = acos(-1.0);
const double eps = 1e-10;

typedef long long LL;
typedef int itn;

const int maxn = 500007;
const int maxm = 0;

char buffer[16];

int n, m, q;
int w[16];

int s[maxn];

int results[maxn];

inline int read_binary()
{
  int v = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  do
  {
    v = (v << 1) | (ch - '0');
    ch = getchar();
  } while (isdigit(ch));
  return v;
}

struct Query
{
  int id;
  int s;
  int k;

  void read(int id)
  {
    this->id = id;
    s = read_binary();
    scanf("%d", &k);
  }

  bool operator <(const Query &rhs) const
  {
    return k < rhs.k;
  }

}query[maxn];

//std::map<int, int> smap;
int smap[8192];
std::vector<Query> qmap[8192];
//std::map<int, std::vector<Query>> qmap;

int qs[maxn];
int qsn;
int sn;

inline void read()
{
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < n; i++) scanf("%d", w + i);

  for (int i = 0; i < m; i++) s[i] = read_binary();

  for (int i = 0; i < q; i++) query[i].read(i);

}

int wus[4096];

inline void init()
{
  memset(wus, 0, sizeof wus);
  memset(smap, 0, sizeof smap);

  for (int i = 0; i < m; i++)
  {
    smap[s[i]]++;
  }

  for (int i = 0; i < q; i++)
  {
    qmap[query[i].s].push_back(query[i]);
    qs[i] = query[i].s;
  }

  std::sort(qs, qs + q);
  qsn = std::unique(qs, qs + q) - qs;

  std::sort(s, s + m);
  sn = std::unique(s, s + m) - s;

  //for (auto &e : qmap)
  for (int qi = 0; qi < qsn; qi++)
  {
    auto &v = qmap[qs[qi]];
    std::sort(v.begin(), v.end());
  }
}

inline int ith_bit(int s, int i)
{
  return s & (1 << (n - i - 1));
}

inline int calc_wu(int s, int t)
{
  int wu = 0;
  for (int i = 0; i < n; i++)
  {
    if (ith_bit(s, i) == ith_bit(t, i))
    {
      wu += w[i];
    }
  }
  return wu;
}

void solve()
{
  //for (auto &e: qmap)
  for (int qi = 0; qi < qsn; qi++)
  {
    int t = qs[qi];
    auto &v = qmap[t];
    //printf("gao %d\n", t);
    //for (auto &se : smap)
    memset(wus, 0, sizeof wus);
    for (int si = 0; si < sn; si++)
    {
      int s = ::s[si];
      int cnt = smap[s];
      int wu = calc_wu(s, t);
      wus[wu] += cnt;
      //printf("s = %d, wu = %d, cnt = %d\n", s, wu, cnt);
    }
    //std::sort(wus.begin(), wus.end());
    // stat
    int sum_wu = 0;
    for (int i = 0, j = 0; i < v.size(); i++)
    {
      Query &q = v[i];
      while (j <= q.k)
      {
        sum_wu += wus[j];
        j++;
      }
      results[q.id] = sum_wu;
    }
    //puts("----");
  }
}

inline void print()
{
  for (int i = 0; i < q; i++) printf("%d\n", results[i]);
}

int main()
{
#ifdef FCBRUCE
  freopen("/Users/fcbruce/code/acm/t", "r", stdin);
#endif // FCBRUCE

  read();

  init();

  solve();

  print();

  return 0;
}


/*
 *
 * Author : fcbruce <fcbruce8964@gmail.com>
 *
 * Time : Wed 08 Aug 2018 22:53:27
 *
 */
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif

const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const double PI = acos(-1.0);
const double eps = 1e-10;

typedef long long LL;
typedef int itn;

const int maxn = 500007;
const int maxm = 0;

char buffer[16];

int n, m, q;
int w[16];

int s[maxn];

int results[maxn];

inline int read_binary()
{
  scanf("%s", buffer);
  int v = 0;
  for (int i = 0; i < n; i++)
  {
    v = (v << 1) | (buffer[i] - '0');
  }
  return v;
}

struct Query
{
  int id;
  int s;
  int k;

  void read(int id)
  {
    this->id = id;
    s = read_binary();
    scanf("%d", &k);
  }

  bool operator <(const Query &rhs) const
  {
    return k < rhs.k;
  }

}query[maxn];

//std::map<int, int> smap;
int smap[8192];
std::vector<Query> qmap[8192];
//std::map<int, std::vector<Query>> qmap;

int qs[maxn];
int qsn;
int sn;

inline void read()
{
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < n; i++) scanf("%d", w + i);

  for (int i = 0; i < m; i++) s[i] = read_binary();

  for (int i = 0; i < q; i++) query[i].read(i);

}

std::vector<std::pair<int, int>> wus;
inline void init()
{
  wus.reserve(32768);
  memset(smap, 0, sizeof smap);

  for (int i = 0; i < m; i++)
  {
    smap[s[i]]++;
  }

  for (int i = 0; i < q; i++)
  {
    qmap[query[i].s].push_back(query[i]);
    qs[i] = query[i].s;
  }

  std::sort(qs, qs + q);
  qsn = std::unique(qs, qs + q) - qs;

  std::sort(s, s + m);
  sn = std::unique(s, s + m) - s;

  //for (auto &e : qmap)
  for (int qi = 0; qi < qsn; qi++)
  {
    auto &v = qmap[qs[qi]];
    std::sort(v.begin(), v.end());
  }
}

inline int ith_bit(int s, int i)
{
  return s & (1 << (n - i - 1));
}

inline int calc_wu(int s, int t)
{
  int wu = 0;
  for (int i = 0; i < n; i++)
  {
    if (ith_bit(s, i) == ith_bit(t, i))
    {
      wu += w[i];
    }
  }
  return wu;
}

void solve()
{
  //for (auto &e: qmap)
  for (int qi = 0; qi < qsn; qi++)
  {
    int t = qs[qi];
    auto &v = qmap[t];
    //printf("gao %d\n", t);
    //for (auto &se : smap)
    wus.clear();
    for (int si = 0; si < sn; si++)
    {
      int s = ::s[si];
      int cnt = smap[s];
      int wu = calc_wu(s, t);
      wus.push_back(std::make_pair(wu, cnt));
      //printf("s = %d, wu = %d, cnt = %d\n", s, wu, cnt);
    }
    std::sort(wus.begin(), wus.end());
    // stat
    int sum_wu = 0;
    for (int i = 0, j = 0; i < v.size() && j < wus.size(); i++)
    {
      Query &q = v[i];
      while (j < wus.size() && wus[j].first <= q.k)
      {
        sum_wu += wus[j].second;
        j++;
      }
      results[q.id] = sum_wu;
    }
    //puts("----");
  }
}

inline void print()
{
  for (int i = 0; i < q; i++) printf("%d\n", results[i]);
}

int main()
{
#ifdef FCBRUCE
  freopen("/Users/fcbruce/code/acm/t", "r", stdin);
#endif // FCBRUCE

  read();

  init();

  solve();

  print();

  return 0;
}


/*
 *
 * Author : fcbruce <fcbruce8964@gmail.com>
 *
 * Time : Wed 08 Aug 2018 22:53:27
 *
 */
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif

const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const double PI = acos(-1.0);
const double eps = 1e-10;

typedef long long LL;
typedef int itn;

const int maxn = 100007;
const int maxm = 0;

char buffer[16];

int n, m, q;
int w[16];

int s[maxn];

long long results[maxn];

inline int read_binary()
{
  scanf("%s", buffer);
  int v = 0;
  for (int i = 0; i < n; i++)
  {
    v = v << 1 | (buffer[i] - '0');
  }
  return v;
}

struct Query
{
  int id;
  int s;
  int k;

  void read(int id)
  {
    this->id = id;
    s = read_binary();
    scanf("%d", &k);
  }

  bool operator <(const Query &rhs) const
  {
    return k < rhs.k;
  }

}query[maxn];

std::map<int, int> smap;
std::map<int, std::vector<Query>> qmap;

inline void read()
{
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < n; i++) scanf("%d", w + i);

  for (int i = 0; i < m; i++) s[i] = read_binary();

  for (int i = 0; i < q; i++) query[i].read(i);
}

inline void init()
{
  for (int i = 0; i < m; i++)
  {
    smap[s[i]]++;
  }

  for (int i = 0; i < q; i++)
  {
    qmap[query[i].s].push_back(query[i]);
  }

  for (auto &e : qmap)
  {
    auto &v = e.second;
    std::sort(v.begin(), v.end());
  }
}

inline int ith_bit(int s, int i)
{
  return s & (1 << (n - i - 1));
}

inline int calc_wu(int s, int t)
{
  int wu = 0;
  for (int i = 0; i < n; i++)
  {
    if (ith_bit(s, i) == ith_bit(t, i))
    {
      wu += w[i];
    }
  }
  return wu;
}

void solve()
{
  for (auto &e: qmap)
  {
    int t = e.first;
    auto &v = e.second;
    //printf("gao %d\n", t);
    std::vector<std::pair<int, int>> wus;
    for (auto &se : smap)
    {
      int s = se.first;
      int cnt = se.second;
      int wu = calc_wu(s, t);
      wus.push_back(std::make_pair(wu, cnt));
      //printf("s = %d, wu = %d, cnt = %d\n", s, wu, cnt);
    }
    std::sort(wus.begin(), wus.end());
    // stat
    long long sum_wu = 0;
    for (int i = 0, j = 0; i < v.size() && j < wus.size(); i++)
    {
      Query &q = v[i];
      while (j < wus.size() && wus[j].first <= q.k)
      {
        sum_wu += wus[j].second;
        j++;
      }
      results[q.id] = sum_wu;
    }
    //puts("----");
  }
}

inline void print()
{
  for (int i = 0; i < q; i++) printf(lld "\n", results[i]);
}

int main()
{
#ifdef FCBRUCE
  freopen("/Users/fcbruce/code/acm/t", "r", stdin);
#endif // FCBRUCE

  read();

  init();

  solve();

  print();

  return 0;
}


/*
 *
 * Author : fcbruce <fcbruce8964@gmail.com>
 *
 * Time : Wed 08 Aug 2018 22:53:27
 *
 */
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif

const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const double PI = acos(-1.0);
const double eps = 1e-10;

typedef long long LL;
typedef int itn;

const int maxn = 500007;
const int maxm = 0;

char buffer[16];

int n, m, q;
int w[16];

int s[maxn];

int results[maxn];

inline int read_binary()
{
  int v = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  do
  {
    v = (v << 1) | (ch - '0');
    ch = getchar();
  } while (isdigit(ch));
  return v;
}

struct Query
{
  int id;
  int s;
  int k;

  void read(int id)
  {
    this->id = id;
    s = read_binary();
    scanf("%d", &k);
  }

  bool operator <(const Query &rhs) const
  {
    return k < rhs.k;
  }

}query[maxn];

//std::map<int, int> smap;
int smap[8192];
std::vector<Query> qmap[8192];
//std::map<int, std::vector<Query>> qmap;

int qs[maxn];
int qsn;
int sn;

inline void read()
{
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < n; i++) scanf("%d", w + i);

  for (int i = 0; i < m; i++) s[i] = read_binary();

  for (int i = 0; i < q; i++) query[i].read(i);

}

std::vector<std::pair<int, int>> wus;
inline void init()
{
  wus.reserve(32768);
  memset(smap, 0, sizeof smap);

  for (int i = 0; i < m; i++)
  {
    smap[s[i]]++;
  }

  for (int i = 0; i < q; i++)
  {
    qmap[query[i].s].push_back(query[i]);
    qs[i] = query[i].s;
  }

  std::sort(qs, qs + q);
  qsn = std::unique(qs, qs + q) - qs;

  std::sort(s, s + m);
  sn = std::unique(s, s + m) - s;

  //for (auto &e : qmap)
  for (int qi = 0; qi < qsn; qi++)
  {
    auto &v = qmap[qs[qi]];
    std::sort(v.begin(), v.end());
  }
}

inline int ith_bit(int s, int i)
{
  return s & (1 << (n - i - 1));
}

inline int calc_wu(int s, int t)
{
  int wu = 0;
  for (int i = 0; i < n; i++)
  {
    if (ith_bit(s, i) == ith_bit(t, i))
    {
      wu += w[i];
    }
  }
  return wu;
}

void solve()
{
  //for (auto &e: qmap)
  for (int qi = 0; qi < qsn; qi++)
  {
    int t = qs[qi];
    auto &v = qmap[t];
    //printf("gao %d\n", t);
    //for (auto &se : smap)
    wus.clear();
    for (int si = 0; si < sn; si++)
    {
      int s = ::s[si];
      int cnt = smap[s];
      int wu = calc_wu(s, t);
      wus.push_back(std::make_pair(wu, cnt));
      //printf("s = %d, wu = %d, cnt = %d\n", s, wu, cnt);
    }
    std::sort(wus.begin(), wus.end());
    // stat
    int sum_wu = 0;
    for (int i = 0, j = 0; i < v.size() && j < wus.size(); i++)
    {
      Query &q = v[i];
      while (j < wus.size() && wus[j].first <= q.k)
      {
        sum_wu += wus[j].second;
        j++;
      }
      results[q.id] = sum_wu;
    }
    //puts("----");
  }
}

inline void print()
{
  for (int i = 0; i < q; i++) printf("%d\n", results[i]);
}

int main()
{
#ifdef FCBRUCE
  freopen("/Users/fcbruce/code/acm/t", "r", stdin);
#endif // FCBRUCE

  read();

  init();

  solve();

  print();

  return 0;
}


/*
 *
 * Author : fcbruce <fcbruce8964@gmail.com>
 *
 * Time : Wed 08 Aug 2018 22:53:27
 *
 */
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif

const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const double PI = acos(-1.0);
const double eps = 1e-10;

typedef long long LL;
typedef int itn;

const int maxn = 500007;
const int maxm = 0;

char buffer[16];

int n, m, q;
int w[16];

int s[maxn];

long long results[maxn];

inline int read_binary()
{
  scanf("%s", buffer);
  int v = 0;
  for (int i = 0; i < n; i++)
  {
    v = (v << 1) | (buffer[i] - '0');
  }
  return v;
}

struct Query
{
  int id;
  int s;
  int k;

  void read(int id)
  {
    this->id = id;
    s = read_binary();
    scanf("%d", &k);
  }

  bool operator <(const Query &rhs) const
  {
    return k < rhs.k;
  }

}query[maxn];

std::map<int, int> smap;
std::map<int, std::vector<Query>> qmap;

inline void read()
{
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < n; i++) scanf("%d", w + i);

  for (int i = 0; i < m; i++) s[i] = read_binary();

  for (int i = 0; i < q; i++) query[i].read(i);
}

inline void init()
{
  for (int i = 0; i < m; i++)
  {
    smap[s[i]]++;
  }

  for (int i = 0; i < q; i++)
  {
    qmap[query[i].s].push_back(query[i]);
  }

  for (auto &e : qmap)
  {
    auto &v = e.second;
    std::sort(v.begin(), v.end());
  }
}

inline int ith_bit(int s, int i)
{
  return s & (1 << (n - i - 1));
}

inline int calc_wu(int s, int t)
{
  int wu = 0;
  for (int i = 0; i < n; i++)
  {
    if (ith_bit(s, i) == ith_bit(t, i))
    {
      wu += w[i];
    }
  }
  return wu;
}

void solve()
{
  for (auto &e: qmap)
  {
    int t = e.first;
    auto &v = e.second;
    //printf("gao %d\n", t);
    std::vector<std::pair<int, int>> wus;
    for (auto &se : smap)
    {
      int s = se.first;
      int cnt = se.second;
      int wu = calc_wu(s, t);
      wus.push_back(std::make_pair(wu, cnt));
      //printf("s = %d, wu = %d, cnt = %d\n", s, wu, cnt);
    }
    std::sort(wus.begin(), wus.end());
    // stat
    long long sum_wu = 0;
    for (int i = 0, j = 0; i < v.size() && j < wus.size(); i++)
    {
      Query &q = v[i];
      while (j < wus.size() && wus[j].first <= q.k)
      {
        sum_wu += wus[j].second;
        j++;
      }
      results[q.id] = sum_wu;
    }
    //puts("----");
  }
}

inline void print()
{
  for (int i = 0; i < q; i++) printf(lld "\n", results[i]);
}

int main()
{
#ifdef FCBRUCE
  freopen("/Users/fcbruce/code/acm/t", "r", stdin);
#endif // FCBRUCE

  read();

  init();

  solve();

  print();

  return 0;
}


/*
 *
 * Author : fcbruce <fcbruce8964@gmail.com>
 *
 * Time : Wed 08 Aug 2018 22:53:27
 *
 */
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif

const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const double PI = acos(-1.0);
const double eps = 1e-10;

typedef long long LL;
typedef int itn;

const int maxn = 500007;
const int maxm = 0;

char buffer[16];

int n, m, q;
int w[16];

int s[maxn];

long long results[maxn];

inline int read_binary()
{
  scanf("%s", buffer);
  int v = 0;
  for (int i = 0; i < n; i++)
  {
    v = (v << 1) | (buffer[i] - '0');
  }
  return v;
}

struct Query
{
  int id;
  int s;
  int k;

  void read(int id)
  {
    this->id = id;
    s = read_binary();
    scanf("%d", &k);
  }

  bool operator <(const Query &rhs) const
  {
    return k < rhs.k;
  }

}query[maxn];

//std::map<int, int> smap;
int smap[8192];
std::vector<Query> qmap[8192];
//std::map<int, std::vector<Query>> qmap;

int qs[maxn];
int qsn;
int sn;

inline void read()
{
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < n; i++) scanf("%d", w + i);

  for (int i = 0; i < m; i++) s[i] = read_binary();

  for (int i = 0; i < q; i++) query[i].read(i);

}

std::vector<std::pair<int, int>> wus;
inline void init()
{
  wus.reserve(32768);
  memset(smap, 0, sizeof smap);

  for (int i = 0; i < m; i++)
  {
    smap[s[i]]++;
  }

  for (int i = 0; i < q; i++)
  {
    qmap[query[i].s].push_back(query[i]);
    qs[i] = query[i].s;
  }

  std::sort(qs, qs + q);
  qsn = std::unique(qs, qs + q) - qs;

  std::sort(s, s + m);
  sn = std::unique(s, s + m) - s;

  //for (auto &e : qmap)
  for (int qi = 0; qi < qsn; qi++)
  {
    auto &v = qmap[qs[qi]];
    std::sort(v.begin(), v.end());
  }
}

inline int ith_bit(int s, int i)
{
  return s & (1 << (n - i - 1));
}

inline int calc_wu(int s, int t)
{
  int wu = 0;
  for (int i = 0; i < n; i++)
  {
    if (ith_bit(s, i) == ith_bit(t, i))
    {
      wu += w[i];
    }
  }
  return wu;
}

void solve()
{
  //for (auto &e: qmap)
  for (int qi = 0; qi < qsn; qi++)
  {
    int t = qs[qi];
    auto &v = qmap[t];
    //printf("gao %d\n", t);
    //for (auto &se : smap)
    wus.clear();
    for (int si = 0; si < sn; si++)
    {
      int s = ::s[si];
      int cnt = smap[s];
      int wu = calc_wu(s, t);
      wus.push_back(std::make_pair(wu, cnt));
      //printf("s = %d, wu = %d, cnt = %d\n", s, wu, cnt);
    }
    std::sort(wus.begin(), wus.end());
    // stat
    long long sum_wu = 0;
    for (int i = 0, j = 0; i < v.size() && j < wus.size(); i++)
    {
      Query &q = v[i];
      while (j < wus.size() && wus[j].first <= q.k)
      {
        sum_wu += wus[j].second;
        j++;
      }
      results[q.id] = sum_wu;
    }
    //puts("----");
  }
}

inline void print()
{
  for (int i = 0; i < q; i++) printf(lld "\n", results[i]);
}

int main()
{
#ifdef FCBRUCE
  freopen("/Users/fcbruce/code/acm/t", "r", stdin);
#endif // FCBRUCE

  read();

  init();

  solve();

  print();

  return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int M = (1 << 12) + 5;
int w[M],cnt[M],sum[M][105];
int n,m,q,K;
char s[15];

int statu() {
	int x = 0;
	rep(j,0,n-1) {
		if(s[j]=='1') {
			x+=1<<(n-j-1);
		}
	}
	return x;
}
int main() {
	//freopen("in.txt","r",stdin);
	scanf("%d %d %d",&n,&m,&q);
	rep(i,1,n) scanf("%d",&w[i]);
	rep(i,1,m) {
		scanf("%s",s);
		cnt[statu()]++;
	}
	int nn = (1 << 12) - 1;

	rep(i,0,nn) {
		rep(j,1,100) {
			sum[i][j] += sum[i][j-1];
		}
	}
	while(q--) {
		scanf("%s %d",s,&K);
		printf("%d\n",sum[statu()][K]);
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5010;
ll i,j,l,t,n,m,q,cnt[N],x[N],a,s[N],sum,w,k,ans[N][110];
int main()
{
    map<ll,int>vis;
    scanf("%lld%lld%lld",&n,&m,&q);
    for(i=0;i<n;i++)
        scanf("%lld",&x[i]);
    for(i=0;i<(1<<n);i++)
    {
        for(sum=t=0,j=n;j>=0;j--)
        {
            l=(i>>j)&1;
            t=t*10+l;
            if(l==0)
                sum+=x[n-j-1];
        }
        vis[t]=i;
        s[i]=sum;
    }
    memset(cnt,0,sizeof(cnt));
    for(i=0;i<m;i++)
    {
        scanf("%lld",&a);
        cnt[vis[a]]++;
    }
    for(i=0;i<(1<<n);i++)
    {
        for(j=0;j<(1<<n);j++)
        {
            l=i^j;
            if(s[l]<=100)
                ans[i][s[l]]+=cnt[j];
        }
    }
    while(q--)
    {
        scanf("%lld%lld",&w,&k);
        for(sum=i=0;i<=k;i++)
            sum+=ans[vis[w]][i];
        printf("%lld\n",sum);
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=50010;
ll i,j,t,n,m,q,x[N],a[N*10],s[N],sum,w,k;
int main()
{
    map<ll,int>vis;
    vector<int>ans[N];
    scanf("%lld%lld%lld",&n,&m,&q);
    for(i=0;i<n;i++)
        scanf("%lld",&x[i]);
    for(i=0;i<m;i++)
        scanf("%lld",&a[i]);
    for(i=0;i<(1<<n);i++)
    {
        for(sum=t=0,j=n;j>=0;j--)
        {
            int l=(i>>j)&1;
            t=t*10+l;
            if(l==0)
                sum+=x[n-j-1];
        }
        vis[t]=i;
        s[i]=sum;
    }
    for(i=0;i<(1<<n);i++)
    {
        for(j=0;j<m;j++)
        {
            ans[i].push_back(s[(i^vis[a[j]])]);
        }
        sort(ans[i].begin(),ans[i].end());
    }
    while(q--)
    {
        scanf("%lld%lld",&w,&k);
        sum=upper_bound(ans[vis[w]].begin(),ans[vis[w]].end(),k)-ans[vis[w]].begin();
        printf("%lld\n",sum);
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5010;
ll i,j,l,t,n,m,q,cnt[N],x[N],a[N],s[N],sum,w,k,ans[N][110];
int main()
{
    map<ll,int>vis;
    scanf("%lld%lld%lld",&n,&m,&q);
    for(i=0;i<n;i++)
        scanf("%lld",&x[i]);
    for(i=0;i<(1<<n);i++)
    {
        for(sum=t=0,j=n;j>=0;j--)
        {
            l=(i>>j)&1;
            t=t*10+l;
            if(l==0)
                sum+=x[n-j-1];
        }
        vis[t]=i;
        s[i]=sum;
    }
    memset(cnt,0,sizeof(cnt));
    for(i=0;i<m;i++)
    {
        scanf("%lld",&a[i]);
        cnt[vis[a[i]]]++;
    }
    for(i=0;i<(1<<n);i++)
    {
        for(j=0;j<(1<<n);j++)
        {
            l=i^j;
            if(s[l]<=100)
                ans[i][s[l]]+=cnt[j];
        }
    }
    while(q--)
    {
        scanf("%lld%lld",&w,&k);
        for(sum=i=0;i<=k;i++)
            sum+=ans[vis[w]][i];
        printf("%lld\n",sum);
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100010;
ll i,j,t,n,m,q,x[N],a[N],s[N],sum,w,k;
int main()
{
    map<ll,int>vis;
    vector<int>ans[N];
    scanf("%lld%lld%lld",&n,&m,&q);
    for(i=0;i<n;i++)
        scanf("%lld",&x[i]);
    for(i=0;i<m;i++)
        scanf("%lld",&a[i]);
    for(i=0;i<(1<<n);i++)
    {
        for(sum=t=0,j=n;j>=0;j--)
        {
            int l=(i>>j)&1;
            t=t*10+l;
            if(l==0)
                sum+=x[n-j-1];
        }
        vis[t]=i;
        s[i]=sum;
    }
    for(i=0;i<(1<<n);i++)
    {
        for(j=0;j<m;j++)
        {
            ans[i].push_back(s[(i^vis[a[j]])]);
        }
        sort(ans[i].begin(),ans[i].end());
    }
    while(q--)
    {
        scanf("%lld%lld",&w,&k);
        sum=upper_bound(ans[vis[w]].begin(),ans[vis[w]].end(),k)-ans[vis[w]].begin();
        printf("%lld\n",sum);
    }
    return 0;
}


#include<bits/stdc++.h>
#define mx 4100
using namespace std;
int dp[mx][105];
int freq[mx];
main(){
	//freopen("input.txt","r",stdin);
	int n,m,q;
	cin>>n>>m>>q;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	reverse(arr,arr+n);
	for(int i=0;i<m;i++){
		int mask = 0;
		string str;
		cin>>str;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		freq[mask]++;
	}
	for(int i=0;i<mx;i++){
		for(int j=0;j<mx;j++){
			int sum = 0;
			int p = i;
			int q = j;
			for(int k=0;k<n;k++){
				if(p % 2 == q % 2){
					sum += arr[k];
				}
				p = p / 2;
				q = q / 2;
			}
			if(sum <= 100){
				dp[i][sum] += freq[j];
			}
		}
	}
	for(int i=0;i<mx;i++){
		for(int j=1;j<=100;j++){
			dp[i][j] += dp[i][j-1];
		}
	}
	while(q--){
		string str;
		cin>>str;
		int num;
		cin>>num;
		int mask = 0;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		cout<<dp[mask][num]<<"\n";

	}

}


#include<bits/stdc++.h>
#define mx 4100
using namespace std;
int dp[mx][105];
int freq[mx];
main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	freopen("input.txt","r",stdin);
	int n,m,q;
	cin>>n>>m>>q;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	//reverse(arr,arr+n);
	for(int i=0;i<m;i++){
		int mask = 0;
		string str;
		cin>>str;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		freq[mask]++;
	}
	for(int i=0;i<mx;i++){
		for(int j=0;j<mx;j++){
			int it = i, jt = j, wt = 0;

			for (int k=0; k<n; k++) {
				if (((it ^ jt) & 1) == 0)
					wt += arr[k];
				it >>= 1;
				jt >>= 1;
			}
			if(wt <= 100){
				dp[i][wt] += freq[j];
			}
		}
	}
	for(int i=0;i<mx;i++){
		for(int j=1;j<=100;j++){
			dp[i][j] += dp[i][j-1];
		}
	}
	while(q--){
		string str;
		cin>>str;
		int num;
		cin>>num;
		int mask = 0;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		cout<<dp[mask][num]<<endl;
	}

}


#include<bits/stdc++.h>
#define mx 4100
#define endl "\n"
using namespace std;
int dp[mx][105];
int freq[mx];
main(){
	//freopen("input.txt","r",stdin);
	int n,m,q;
	cin>>n>>m>>q;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	reverse(arr,arr+n);
	for(int i=0;i<m;i++){
		int mask = 0;
		string str;
		cin>>str;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		freq[mask]++;
	}
	for(int i=0;i<mx;i++){
		for(int j=0;j<mx;j++){
			int sum = 0;
			int p = i;
			int q = j;
			for(int k=0;k<n;k++){
				if(p % 2 == q % 2){
					sum += arr[k];
				}
				p = p / 2;
				q = q / 2;
			}
			if(sum <= 100){
				dp[i][sum] += freq[j];
			}
		}
	}
	for(int i=0;i<mx;i++){
		for(int j=1;j<=100;j++){
			dp[i][j] += dp[i][j-1];
		}
	}
	while(q--){
		string str;
		cin>>str;
		int num;
		cin>>num;
		int mask = 0;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		cout<<dp[mask][num]<<endl;

	}

}


#include<bits/stdc++.h>
#define mx 4100
using namespace std;
int dp[mx][105];
int freq[mx];
main(){
	//freopen("input.txt","r",stdin);
	int n,m,q;
	cin>>n>>m>>q;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	//reverse(arr,arr+n);
	for(int i=0;i<m;i++){
		int mask = 0;
		string str;
		cin>>str;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		freq[mask]++;
	}
	for(int i=0;i<mx;i++){
		for(int j=0;j<mx;j++){
			int sum = 0;
			int p = i^j;
			for (int k = 0; k < n; ++k)
			{
				if(!(p & (1<<k))){
					sum += arr[n-k-1];
				}
			}
			if(sum <= 100){
				dp[i][sum] += freq[j];
			}
		}
	}
	for(int i=0;i<mx;i++){
		for(int j=1;j<=100;j++){
			dp[i][j] += dp[i][j-1];
		}
	}
	while(q--){
		string str;
		cin>>str;
		int num;
		cin>>num;
		int mask = 0;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		cout<<dp[mask][num]<<"\n";

	}

}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int n, m, q;
int w[12];
int c[4096];

int r[4096][105];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> n >> m >> q;
	for (int i=0; i<n; i++)
		cin >> w[i];

	reverse(w, w+n);

	for (int i=0; i<m; i++) {
		string s;
		cin >> s;
		int mask = 0;
		for (char x : s)
			mask = 2*mask + (x - '0');
		c[mask]++;
	}

	// resi unapred
	for (int i=0; i<(1<<n); i++) {
		for (int j=0; j<(1<<n); j++) {

			int it = i, jt = j, wt = 0;

			for (int k=0; k<n; k++) {
				if (((it ^ jt) & 1) == 0)
					wt += w[k];
				it >>= 1;
				jt >>= 1;
			}

			if (wt <= 100)
				r[j][wt] += c[i];
		}
	}

	for (int i=0; i<(1<<n); i++)
		for (int j=1; j<=100; j++)
			r[i][j] += r[i][j-1];

	// radi
	for (int i=0; i<q; i++) {
		string s;
		cin >> s;
		int k;
		cin >> k;
		int mask = 0;
		for (char x : s)
			mask = 2*mask + (x - '0');
		cout << r[mask][k] << '\n';
	}
}


#include<bits/stdc++.h>
#define mx 4100
using namespace std;
int dp[mx][105];
int freq[mx];
main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//	freopen("input.txt","r",stdin);
	int n,m,q;
	cin>>n>>m>>q;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	//reverse(arr,arr+n);
	for(int i=0;i<m;i++){
		int mask = 0;
		string str;
		cin>>str;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		freq[mask]++;
	}
	for(int i=0;i<mx;i++){
		for(int j=0;j<mx;j++){
			int p = i^j;
			int sum = 0;
			for (int k = 0; k < n; ++k)
			{
				if(!(p & (1<<k))){
					sum += arr[n-k-1];
				}
			}
			if(sum <= 100){
				dp[i][sum] += freq[j];
			}
		}
	}
	for(int i=0;i<mx;i++){
		for(int j=1;j<=100;j++){
			dp[i][j] += dp[i][j-1];
		}
	}
	while(q--){
		string str;
		cin>>str;
		int num;
		cin>>num;
		int mask = 0;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		cout<<dp[mask][num]<<"\n";
	}

}


#include<bits/stdc++.h>
#define mx 4100
using namespace std;
int dp[mx][105];
int freq[mx];
main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//	freopen("input.txt","r",stdin);
	int n,m,q;
	cin>>n>>m>>q;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	reverse(arr,arr+n);
	for(int i=0;i<m;i++){
		int mask = 0;
		string str;
		cin>>str;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		freq[mask]++;
	}
	for(int i=0;i<mx;i++){
		for(int j=0;j<mx;j++){
			int it = i, jt = j, wt = 0;

			for (int k=0; k<n; k++) {
				if (((it ^ jt) & 1) == 0)
					wt += arr[k];
				it >>= 1;
				jt >>= 1;
			}
			if(wt <= 100){
				dp[i][wt] += freq[j];
			}
		}
	}
	for(int i=0;i<mx;i++){
		for(int j=1;j<=100;j++){
			dp[i][j] += dp[i][j-1];
		}
	}
	while(q--){
		string str;
		cin>>str;
		int num;
		cin>>num;
		int mask = 0;
		int count = 0;
		for(int j=n-1;j>=0;j--){
			mask += (str[j]-'0')*pow(2,count++);
		}
		cout<<dp[mask][num]<<endl;
	}

}