#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int wu(int u, int v, vector<int>* w) {
    int answer = 0;
    for (size_t i = 0; i < (*w).size(); i++)
        if ((u >> i & 1) == (v >> i & 1)) answer += w->at((*w).size() - 1 - i);

    return answer;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k, MAXW = 1;
    string s, t;

    cin >> n >> m >> q;
    vector<int> w(n);
    for (int i = 0; i < n; i++){
        cin >> w[i];
        MAXW += w[i];
    }
    MAXW = min(101, MAXW);
    unordered_map<int, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(bitset<12>(s).to_ulong())) S[bitset<12>(s).to_ulong()]++;
        else S[bitset<12>(s).to_ulong()] = 1;
    }

    vector<vector<int>> wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++)
        wu_table[i] = vector<int>(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i; j < (1 << n); j++) {
            wu_table[i][j] = wu(i, j, &w);
            wu_table[j][i] = wu_table[i][j];
        }
    }

    vector<vector<int>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        test_wu_table[i] = vector<int>(MAXW, 0);
        for (auto s: S)
            if (wu_table[i][s.first] < MAXW) test_wu_table[i][wu_table[i][s.first]] += s.second;

        for (int j = 1; j <= MAXW - 1; j++){
            test_wu_table[i][j] += test_wu_table[i][j - 1];
        }
    }

    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        cout << test_wu_table[t_v][min(k, MAXW - 1)] << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int wu(int u, int v, vector<int>* w) {
    int answer = 0;
    for (size_t i = 0; i < (*w).size(); i++)
        if ((u >> i & 1) == (v >> i & 1)) answer += w->at((*w).size() - 1 - i);

    return answer;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k;
    string s, t;

    cin >> n >> m >> q;
    vector<int> w(n);
    for (int i = 0; i < n; i++){
        cin >> w[i];
    }
    unordered_map<int, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(bitset<12>(s).to_ulong())) S[bitset<12>(s).to_ulong()]++;
        else S[bitset<12>(s).to_ulong()] = 1;
    }

    vector<vector<int>> wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++)
        wu_table[i] = vector<int>(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i; j < (1 << n); j++) {
            wu_table[i][j] = wu(i, j, &w);
            wu_table[j][i] = wu_table[i][j];
        }
    }

    vector<vector<int>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        test_wu_table[i] = vector<int>(101);
        for (auto s: S)
            if (wu_table[i][s.first] <= 100) test_wu_table[i][wu_table[i][s.first]] += s.second;

        for (int j = 1; j <= 100; j++){
            test_wu_table[i][j] += test_wu_table[i][j - 1];
        }
    }

    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        cout << test_wu_table[t_v][k] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int wu(int u, int v, vector<int>* w) {
    int answer = 0;
    for (size_t i = 0; i < (*w).size(); i++)
        if ((u >> i & 1) == (v >> i & 1)) answer += w->at((*w).size() - 1 - i);

    return answer;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k;
    string s, t;

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

    unordered_map<int, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(bitset<12>(s).to_ulong())) S[bitset<12>(s).to_ulong()]++;
        else S[bitset<12>(s).to_ulong()] = 1;
    }

    vector<vector<int>> wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++)
        wu_table[i] = vector<int>(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i; j < (1 << n); j++) {
            wu_table[i][j] = wu(i, j, &w);
            wu_table[j][i] = wu_table[i][j];
        }
    }

    vector<vector<int>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        test_wu_table[i] = vector<int>(1201, 0);
        for (auto s: S)
            test_wu_table[i][wu_table[i][s.first]] += s.second;

        for (size_t j = 1; j < 1201; j++)
            test_wu_table[i][j] += test_wu_table[i][j - 1];
    }

    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        cout << test_wu_table[t_v][k] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int wu(int u, int v, vector<int>* w) {
    int answer = 0;
    for (size_t i = 0; i < (*w).size(); i++)
        if ((u >> i & 1) == (v >> i & 1)) answer += w->at((*w).size() - 1 - i);

    return answer;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k, MAXW = 1;
    string s, t;

    cin >> n >> m >> q;
    vector<int> w(n);
    for (int i = 0; i < n; i++){
        cin >> w[i];
        MAXW += w[i];
    }
    MAXW = min(101, MAXW);
    unordered_map<int, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(bitset<12>(s).to_ulong())) S[bitset<12>(s).to_ulong()]++;
        else S[bitset<12>(s).to_ulong()] = 1;
    }

    vector<vector<int>> wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++)
        wu_table[i] = vector<int>(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i; j < (1 << n); j++) {
            wu_table[i][j] = wu(i, j, &w);
            wu_table[j][i] = wu_table[i][j];
        }
    }

    vector<vector<int>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        test_wu_table[i] = vector<int>(MAXW, 0);
        for (auto s: S)
            if (wu_table[i][s.first] < MAXW) test_wu_table[i][wu_table[i][s.first]] += s.second;

        for (int j = 1; j <= MAXW - 1; j++){
            test_wu_table[i][j] += test_wu_table[i][j - 1];
        }
    }

    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        cout << test_wu_table[t_v][min(k, MAXW - 1)] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int wu(int u, int v, vector<int>* w) {
    int answer = 0;
    for (size_t i = 0; i < (*w).size(); i++)
        if ((u >> i & 1) == (v >> i & 1)) answer += w->at((*w).size() - 1 - i);

    return answer;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k, MAXW = 1;
    string s, t;

    cin >> n >> m >> q;
    vector<int> w(n);
    for (int i = 0; i < n; i++){
        cin >> w[i];
        MAXW += w[i];
    }
    MAXW = min(101, MAXW);
    unordered_map<int, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(bitset<12>(s).to_ulong())) S[bitset<12>(s).to_ulong()]++;
        else S[bitset<12>(s).to_ulong()] = 1;
    }

    vector<vector<int>> wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++)
        wu_table[i] = vector<int>(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i; j < (1 << n); j++) {
            wu_table[i][j] = wu(i, j, &w);
            wu_table[j][i] = wu_table[i][j];
        }
    }

    vector<vector<int>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        test_wu_table[i] = vector<int>(MAXW);
        for (auto s: S)
            test_wu_table[i][wu_table[i][s.first]] += s.second;

        for (int j = 1; j <= MAXW -1; j++){
            test_wu_table[i][j] += test_wu_table[i][j - 1];
        }
    }

    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        cout << test_wu_table[t_v][min(k, MAXW- 1)] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int wu(int u, int v, vector<int>* w) {
    int answer = 0;
    for (size_t i = 0; i < (*w).size(); i++)
        if ((u >> i & 1) == (v >> i & 1)) answer += w->at((*w).size() - 1 - i);

    return answer;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k, MAXW = 1;
    string s, t;

    cin >> n >> m >> q;
    vector<int> w(n);
    for (int i = 0; i < n; i++){
        cin >> w[i];
        MAXW += w[i];
    }
    unordered_map<int, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(bitset<12>(s).to_ulong())) S[bitset<12>(s).to_ulong()]++;
        else S[bitset<12>(s).to_ulong()] = 1;
    }

    vector<vector<int>> wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++)
        wu_table[i] = vector<int>(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i; j < (1 << n); j++) {
            wu_table[i][j] = wu(i, j, &w);
            wu_table[j][i] = wu_table[i][j];
        }
    }

    vector<vector<int>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        test_wu_table[i] = vector<int>(min(101, MAXW));
        for (auto s: S)
            if (wu_table[i][s.first] <= 100) test_wu_table[i][wu_table[i][s.first]] += s.second;

        for (int j = 1; j <= min(100, MAXW - 1); j++){
            test_wu_table[i][j] += test_wu_table[i][j - 1];
        }
    }

    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        cout << test_wu_table[t_v][min(k, MAXW - 1)] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int wu(int u, int v, vector<int>* w) {
    int answer = 0;
    for (size_t i = 0; i < (*w).size(); i++)
        if ((u >> i & 1) == (v >> i & 1)) answer += w->at((*w).size() - 1 - i);

    return answer;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k, MAXW = 1;
    string s, t;

    cin >> n >> m >> q;
    vector<int> w(n);
    for (int i = 0; i < n; i++){
        cin >> w[i];
        MAXW += w[i];
    }
    MAXW = min(101, MAXW);
    unordered_map<int, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(bitset<12>(s).to_ulong())) S[bitset<12>(s).to_ulong()]++;
        else S[bitset<12>(s).to_ulong()] = 1;
    }

    vector<vector<int>> wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++)
        wu_table[i] = vector<int>(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i; j < (1 << n); j++) {
            wu_table[i][j] = wu(i, j, &w);
            wu_table[j][i] = wu_table[i][j];
        }
    }

    vector<vector<int>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        test_wu_table[i] = vector<int>(MAXW);
        for (auto s: S)
            test_wu_table[i][wu_table[i][s.first]] += s.second;

        for (int j = 1; j <= MAXW -1; j++){
            test_wu_table[i][j] += test_wu_table[i][j - 1];
        }
    }

    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        cout << test_wu_table[t_v][min(k, MAXW - 1)] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int wu(int u, int v, vector<int>* w) {
    int answer = 0;
    for (size_t i = 0; i < (*w).size(); i++)
        if ((u >> i & 1) == (v >> i & 1)) answer += w->at((*w).size() - 1 - i);

    return answer;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k, MAXW = 1;
    string s, t;

    cin >> n >> m >> q;
    vector<int> w(n);
    for (int i = 0; i < n; i++){
        cin >> w[i];
        MAXW += w[i];
    }
    MAXW = min(101, MAXW);
    unordered_map<int, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(bitset<12>(s).to_ulong())) S[bitset<12>(s).to_ulong()]++;
        else S[bitset<12>(s).to_ulong()] = 1;
    }

    vector<vector<int>> wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++)
        wu_table[i] = vector<int>(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i; j < (1 << n); j++) {
            wu_table[i][j] = wu(i, j, &w);
            wu_table[j][i] = wu_table[i][j];
        }
    }

    vector<vector<int>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        test_wu_table[i] = vector<int>(MAXW, 0);
        for (auto s: S)
            test_wu_table[i][min(wu_table[i][s.first], MAXW - 1)] += s.second;

        for (int j = 1; j <= MAXW - 1; j++){
            test_wu_table[i][j] += test_wu_table[i][j - 1];
        }
    }

    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        cout << test_wu_table[t_v][min(k, MAXW - 1)] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int wu(int u, int v, vector<int>* w) {
    int answer = 0;
    for (size_t i = 0; i < (*w).size(); i++)
        if ((u >> i & 1) == (v >> i & 1)) answer += w->at((*w).size() - 1 - i);

    return answer;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k, MAXW = 1;
    string s, t;

    cin >> n >> m >> q;
    vector<int> w(n);
    for (int i = 0; i < n; i++){
        cin >> w[i];
        MAXW += w[i];
    }
    unordered_map<int, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(bitset<12>(s).to_ulong())) S[bitset<12>(s).to_ulong()]++;
        else S[bitset<12>(s).to_ulong()] = 1;
    }

    vector<vector<int>> wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++)
        wu_table[i] = vector<int>(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i; j < (1 << n); j++) {
            wu_table[i][j] = wu(i, j, &w);
            wu_table[j][i] = wu_table[i][j];
        }
    }

    vector<vector<int>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        test_wu_table[i] = vector<int>(MAXW, 0);
        for (auto s: S)
            test_wu_table[i][wu_table[i][s.first]] += s.second;

        for (int j = 1; j < MAXW; j++){
            test_wu_table[i][j] += test_wu_table[i][j - 1];
        }
    }

    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        cout << test_wu_table[t_v][min(k, MAXW - 1)] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int mp[110001];
string a[110001];
int  sum[110011],len;

int  w[101];
int  ans[11300][102];

int zf(string x){

    int sum=0;
    for(int i=0;i<n;i++)
        sum=sum*2+x[i]-'0';
    return sum;
}

int zf(char x[]){

    int sum=0;
    for(int i=0;i<n;i++)
        sum=sum*2+x[i]-'0';
    return sum;
}

void dfs(int i,string b){
    if(i>n)
        return ;
    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];

            ans[d][x]+=sum[k];
        }
    //    cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    char x[20];
    for(int i=0;i<m;i++)
    {
        scanf("%s",x);
        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

    dfs(1,"0");
    dfs(1,"1");

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
map<string,int>mp;
string a[10001];
int  sum[10011],len;

int  w[101];
int  ans[4300][102];

int zf(string x){

    int sum=0;
    for(int i=0;i<n;i++)
        sum=sum*2+x[i]-'0';
    return sum;
}

void dfs(int i,string b){
    if(i>n)
        return ;
    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];

            ans[d][x]+=sum[k];
        }
    //    cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    string x;
    for(int i=0;i<m;i++)
    {
        cin>>x;
        if(!mp[x])
        {
            len++;
            mp[x]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[x]]++;
    }

    dfs(1,"0");
    dfs(1,"1");

    string b;
    int k;
    while(t--)
    {
        cin>>b;
        scanf("%d",&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int   mp[10001];
string a[11001];
int  sum[11011],len;

int    w[101];
int  ans[13000][102];

int zf(string x){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

int zf(char x[]){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

void dfs(int i,string b){
    if(i>n)
        return ;

    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];
            if(x<=100)
                ans[d][x]+=sum[k];
        }
   //     cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    string x;
    for(int i=0;i<m;i++)
    {
        cin>>x;

        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

 //   dfs(1,"0");
   // dfs(1,"1");
    int i=0,mm=1<<n;

    while(i<mm)
    {
        int k=1;
        while(k<=len)
        {
            int d=i,ls=0;
            int j=n-1;
            while(j>=0)
            {

                if(a[k][j]==((d&1)+'0'))
                    ls+=w[j];
                d>>=1;
                j--;
         //       cout<<d<<endl;
            }
       //     printf("%d    %d   ",i,ls);cout<<a[k]<<endl;
            if(ls<=100)
                ans[i][ls]+=sum[k];
            k++;
        }

        for(int k=1;k<=100;k++)
            ans[i][k]+=ans[i][k-1];
        i++;
    }

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
map<string,int>mp;
string a[10001];
int  sum[10011],len;

int  w[101];
int  ans[4300][102];

int zf(string x){

    int sum=0;
    for(int i=0;i<n;i++)
        sum=sum*2+x[i]-'0';
    return sum;
}

void dfs(int i,string b){
    if(i>n)
        return ;
    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];

            ans[d][x]+=sum[k];
        }
    //    cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    string x;
    for(int i=0;i<m;i++)
    {
        cin>>x;
        if(!mp[x])
        {
            len++;
            mp[x]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[x]]++;
    }

    dfs(1,"0");
    dfs(1,"1");

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int   mp[10001];
string a[11001];
int  sum[11011],len;

int    w[101];
int  ans[13000][102];

int zf(string x){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

int zf(char x[]){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

void dfs(int i,string b){
    if(i>n)
        return ;

    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];
            if(x<=100)
                ans[d][x]+=sum[k];
        }
   //     cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    char x[30];
    for(int i=0;i<m;i++)
    {
        scanf("%s",x);

        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

 //   dfs(1,"0");
   // dfs(1,"1");
    int i=0,mm=1<<n;

    while(i<mm)
    {
        int k=1;
        while(k<=len)
        {
            int d=i,ls=0;
            int j=n-1;
            while(j>=0)
            {

                if(a[k][j]==((d&1)+'0'))
                    ls+=w[j];
                d>>=1;
                j--;
         //       cout<<d<<endl;
            }
       //     printf("%d    %d   ",i,ls);cout<<a[k]<<endl;
            if(ls<=100)
                ans[i][ls]+=sum[k];
            k++;
        }

        for(int k=1;k<=100;k++)
            ans[i][k]+=ans[i][k-1];
        i++;
    }

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int mp[10001];
string a[10001];
int  sum[10011],len;

int  w[101];
int  ans[4300][102];

int zf(string x){

    int sum=0;
    for(int i=0;i<n;i++)
        sum=sum*2+x[i]-'0';
    return sum;
}

void dfs(int i,string b){
    if(i>n)
        return ;
    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];

            ans[d][x]+=sum[k];
        }
    //    cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    char x[20];
    for(int i=0;i<m;i++)
    {
        scanf("%s",x);
        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

    dfs(1,"0");
    dfs(1,"1");

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int mp[10001];
string a[10001];
int  sum[10011],len;

int  w[101];
int  ans[4300][102];

int zf(string x){

    int sum=0;
    for(int i=0;i<n;i++)
        sum=sum*2+x[i]-'0';
    return sum;
}
int zf(char x[]){

    int sum=0;
    for(int i=0;i<n;i++)
        sum=sum*2+x[i]-'0';
    return sum;
}
void dfs(int i,string b){
    if(i>n)
        return ;
    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];

            ans[d][x]+=sum[k];
        }
    //    cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    char x[20];
    for(int i=0;i<m;i++)
    {
        scanf("%s",x);
        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

    dfs(1,"0");
    dfs(1,"1");

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int mp[10001];
string a[10001];
int  sum[10011],len;

int  w[101];
int  ans[4300][102];

int zf(string x){

    int sum=0;
    for(int i=0;i<n;i++)
        sum=sum*2+x[i]-'0';
    return sum;
}

void dfs(int i,string b){
    if(i>n)
        return ;
    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];

            ans[d][x]+=sum[k];
        }
    //    cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    string x;
    for(int i=0;i<m;i++)
    {
        cin>>x;
        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

    dfs(1,"0");
    dfs(1,"1");

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int   mp[10001];
string a[11001];
int  sum[11011],len;

int    w[101];
int  ans[13000][102];

int zf(string x){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

int zf(char x[]){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

void dfs(int i,string b){
    if(i>n)
        return ;

    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];
            if(x<=100)
                ans[d][x]+=sum[k];
        }
   //     cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    string x;
    for(int i=0;i<m;i++)
    {
        cin>>x;

        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

 //   dfs(1,"0");
   // dfs(1,"1");
    int i=0,mm=1<<n;

    while(i<mm)
    {

        for(int k=1;k<=len;k++)
        {
            int d=i,ls=0;
            for(int j=n-1;j>=0;j--)
            {

                if(a[k][j]==((d&1)+'0'))
                    ls+=w[j];

                d>>=1;
         //       cout<<d<<endl;
            }
       //     printf("%d    %d   ",i,ls);cout<<a[k]<<endl;
            if(ls<=100)
                ans[i][ls]+=sum[k];
        }

        for(int k=1;k<=100;k++)
            ans[i][k]+=ans[i][k-1];
        i++;
    }

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int   mp[10001];
string a[11001];
int  sum[11011],len;

int    w[101];
int  ans[13000][102];

int zf(string x){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

int zf(char x[]){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

void dfs(int i,string b){
    if(i>n)
        return ;

    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];
            if(x<=100)
                ans[d][x]+=sum[k];
        }
   //     cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    string x;
    for(int i=0;i<m;i++)
    {
        cin>>x;

        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

    dfs(1,"0");
    dfs(1,"1");

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    int i;
    string a;
};
map<string,int>mp;
string a[10001];
int  sum[10011],len;
int w[101];
void dfs(int i,string b)
{
    if(i>n)
        return ;
    if(i==n)
    {
        int x;
        for(int i=1;i<=len;i++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[i][j]==b[j])
                    x+=w[j];
        }
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    string x;
    int ls;
    for(int i=0;i<m;i++)
    {
        cin>>x;
        ls=mp[x];
        if(!ls)
        {
            len++;
            mp[x]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[ls]++;
    }
    /*
    string b="1";
    dfs(1,b);
           b="0";
    dfs(1,b);
    */
    char b[100];
    int k,l,s;
    while(t--)
    {
        scanf("%s%d",b,&k);
        s=0;

        for(int i=1;i<=len;i++)
        {
            l=0;
            for(int j=0;j<n;j++)
                if(b[j]==a[i][j])
                    l+=w[j];
            if(l<=k)
                s+=sum[i];
        }
        cout<<s<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int   mp[10001];
string a[11001];
int  sum[11011],len;

int    w[101];
int  ans[13000][102];

int zf(string x){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

int zf(char x[]){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

void dfs(int i,string b){
    if(i>n)
        return ;

    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];
            if(x<=100)
                ans[d][x]+=sum[k];
        }
   //     cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    string x;
    for(int i=0;i<m;i++)
    {
        cin>>x;

        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

 //   dfs(1,"0");
   // dfs(1,"1");
    int i=0,mm=1<<n;

    while(i<mm)
    {

        for(int k=1;k<=len;k++)
        {
            int d=i,ls=0;
            for(int j=n-1;j>=0;j--)
            {

                if(a[k][j]==((d&1)+'0'))
                    ls+=w[j];

                d/=2;
         //       cout<<d<<endl;
            }
       //     printf("%d    %d   ",i,ls);cout<<a[k]<<endl;
            if(ls<=100)
                ans[i][ls]+=sum[k];
        }

        for(int k=1;k<=100;k++)
            ans[i][k]+=ans[i][k-1];
        i++;
    }

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int   mp[10001];
string a[11001];
int  sum[11011],len;

int    w[101];
int  ans[13000][102];

int zf(string x){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

int zf(char x[]){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

void dfs(int i,string b){
    if(i>n)
        return ;

    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];

            ans[d][x]+=sum[k];
        }
   //     cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    char x[20];
    for(int i=0;i<m;i++)
    {
        scanf("%s",x);
        if(strlen(x)!=n)
        {
            while(1);
        }
        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

    dfs(1,"0");
    dfs(1,"1");

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int mp[110001];
string a[110001];
int  sum[110011],len;

int  w[101];
int  ans[13000][102];

int zf(string x){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

int zf(char x[]){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

void dfs(int i,string b){
    if(i>n)
        return ;

    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];

            ans[d][x]+=sum[k];
        }
   //     cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    char x[20];
    for(int i=0;i<m;i++)
    {
        scanf("%s",x);
        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

    dfs(1,"0");
    dfs(1,"1");

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    string a;
    int i;
};
int   mp[10001];
string a[11001];
int  sum[11011],len;

int    w[101];
int  ans[13000][102];

int zf(string x){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

int zf(char x[]){

    int sm=0;
    for(int i=0;i<n;i++)
        sm=sm*2+x[i]-'0';
    return sm;
}

void dfs(int i,string b){
    if(i>n)
        return ;

    if(i==n)
    {
        int x;
        int d=zf(b);
        for(int k=1;k<=len;k++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[k][j]==b[j])
                    x+=w[j];
            if(x<=100)
                ans[d][x]+=sum[k];
        }
   //     cout<<b<<endl;
        for(int k=1;k<=100;k++)
            ans[d][k]+=ans[d][k-1];
        return ;
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    char x[20];
    for(int i=0;i<m;i++)
    {
        scanf("%s",x);

        int ls=zf(x);
        if(!mp[ls])
        {
            len++;
            mp[ls]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[ls]]++;
    }

    dfs(1,"0");
    dfs(1,"1");

    char b[101];
    int k;
    while(t--)
    {
        scanf("%s%d",b,&k);
        printf("%d\n",ans[zf(b)][k]);
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const   double eps=1e-7;
const   int    MAX=100005;
int n,m;
struct node{
    int i;
    string a;
};
map<string,int>mp;
string a[10001];
int  sum[10011],len;
int w[101];
void dfs(int i,string b)
{
    if(i>n)
        return ;
    if(i==n)
    {
        int x;
        for(int i=1;i<=len;i++)
        {
            x=0;
            for(int j=0;j<n;j++)
                if(a[i][j]==b[j])
                    x+=w[j];
        }
    }
    dfs(i+1,b+"0");
    dfs(i+1,b+"1");
}

int main() {
    int t;

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

    string x;
    for(int i=0;i<m;i++)
    {
        cin>>x;
        if(!mp[x])
        {
            len++;
            mp[x]=len;
            a[len]=x;
            sum[len]=1;
        }
        else
            sum[mp[x]]++;
    }
    /*
    string b="1";
    dfs(1,b);
           b="0";
    dfs(1,b);
    */
    string b;
    int k,l,s;
    while(t--)
    {
        cin>>b;
        scanf("%d",&k);
        s=0;

        for(int i=1;i<=len;i++)
        {
            l=0;
            for(int j=0;j<n;j++)
                if(b[j]==a[i][j])
                    l+=w[j];
            if(l<=k)
                s+=sum[i];
        }
        cout<<s<<endl;
    }
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int n, m, q, w[102], k[5000], a[20], c[5000][5000], d[5000][102];
string p, k2[5000];

int to_num(string p) {
	int num = 0;
	for (int j = 1; j <= p.length(); j++) {
		num += (p[j-1] - '0') * a[p.length() - j];
	}
	return num;
}

string to_str(int b) {
	string temp = {};
	for (int i = n - 1; i >= 0; i--){
		if (b >= a[i]) {
			temp.push_back('1');
			b -= a[i];
		} else {
			temp.push_back('0');
		}
	}
	return temp;
}

int comp(string temp_s, int temp_i) {
	int ans = 0;
	int temp = to_num(temp_s);
	for (int i = 0; i <= temp_i; i++) {
		ans += d[temp][i];
	}
	return ans;
}

int main() {
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}
	a[0] = 1;
	for (int i = 1; i < 13; i++) {
		a[i] = a[i-1] * 2;
	}
	for (int i = 0; i < m; i++) {
		cin >> p;
		k[to_num(p)]++;
	}
	for (int i = 0; i < a[n]; i++) {
		k2[i] = to_str(i);
	}
	for (int i = 0; i < a[n]; i++) {
		for (int j = 0; j < a[n]; j++) {
			for (int k = 0; k < n; k++) {
				if (k2[i][k] == k2[j][k]) {
					c[i][j] += w[k];
				}
			}
		}
	}

	for (int i = 0; i < a[n]; i++) {
		for (int j = 0; j < a[n]; j++) {
			d[i][c[i][j]] += k[j];
		}
	}
	for (int i = 0; i < q; i++) {
		string temp_s;
		int temp_i;
		cin >> temp_s >> temp_i;
		cout << comp(temp_s, temp_i) << endl;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int n, m, q, w[102], k[5000], a[20], c[5000][5000], d[5000][2000], e[5000][2000];
string p, k2[5000];

int to_num(string p) {
	int num = 0;
	for (int j = 1; j <= p.length(); j++) {
		num += (p[j-1] - '0') * a[p.length() - j];
	}
	return num;
}

string to_str(int b) {
	string temp = {};
	for (int i = n - 1; i >= 0; i--){
		if (b >= a[i]) {
			temp.push_back('1');
			b -= a[i];
		} else {
			temp.push_back('0');
		}
	}
	return temp;
}

int main() {
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}
	a[0] = 1;
	for (int i = 1; i < 13; i++) {
		a[i] = a[i-1] * 2;
	}
	for (int i = 0; i < m; i++) {
		cin >> p;
		k[to_num(p)]++;
	}
	for (int i = 0; i < a[n]; i++) {
		k2[i] = to_str(i);
	}
	for (int i = 0; i < a[n]; i++) {
		for (int j = i; j < a[n]; j++) {
			for (int k = 0; k < n; k++) {
				if (k2[i][k] == k2[j][k]) {
					c[i][j] += w[k];
				}
			}
		}
	}
	for (int i = 0; i < a[n]; i++) {
		for (int j = 0; j < a[n]; j++) {
			if (i > j) {
				d[i][c[j][i]] += k[j];
			} else {
				d[i][c[i][j]] += k[j];
			}
		}
	}
	for (int i = 0; i < a[n]; i++) {
		for (int j = 0; j < 2000; j++) {
			if (j == 0) {
				e[i][j] = d[i][j];
			} else {
				e[i][j] = e[i][j-1] + d[i][j];
			}
		}
	}
	for (int i = 0; i < q; i++) {
		string temp_s;
		int temp_i;
		cin >> temp_s >> temp_i;
		int temp = to_num(temp_s);
		cout << e[temp][temp_i] << endl;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int n, m, q, w[102], k[5000], a[20];
string p;

int to_num(string p) {
	int num = 0;
	for (int j = 1; j <= p.length(); j++) {
		num += (p[j-1] - '0') * a[p.length() - j];
	}
	return num;
}

string to_str(int b) {
	string temp = {};
	for (int i = n - 1; i >= 0; i--){
		if (b >= a[i]) {
			temp.push_back('1');
			b -= a[i];
		} else {
			temp.push_back('0');
		}
	}
	return temp;
}

int comp(string temp_s, int temp_i) {
	int ans = 0;
	for (int i = 0; i < a[n]; i++) {
		int value = 0;
		if (k[i] > 0) {
			string abc = to_str(i);
			for (int j = 0; j < n; j++) {
				if (abc[j] == temp_s[j]) {
					value += w[j];
				}
			}
			if (value <= temp_i) {
				ans += k[i];
			}
		}
	}
	return ans;
}

int main() {
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}
	a[0] = 1;
	for (int i = 1; i < 13; i++) {
		a[i] = a[i-1] * 2;
	}
	for (int i = 0; i < m; i++) {
		cin >> p;
		k[to_num(p)]++;
	}
	for (int i = 0; i < q; i++) {
		string temp_s;
		int temp_i;
		cin >> temp_s >> temp_i;
		cout << comp(temp_s, temp_i) << endl;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int n, m, q, w[102], k[5000], a[20], c[5000][5000], d[5000][2000], e[5000][2000];
string p, k2[5000];

int to_num(string p) {
	int num = 0;
	for (int j = 1; j <= p.length(); j++) {
		num += (p[j-1] - '0') * a[p.length() - j];
	}
	return num;
}

string to_str(int b) {
	string temp = {};
	for (int i = n - 1; i >= 0; i--){
		if (b >= a[i]) {
			temp.push_back('1');
			b -= a[i];
		} else {
			temp.push_back('0');
		}
	}
	return temp;
}

int main() {
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}
	a[0] = 1;
	for (int i = 1; i < 13; i++) {
		a[i] = a[i-1] * 2;
	}
	for (int i = 0; i < m; i++) {
		cin >> p;
		k[to_num(p)]++;
	}
	for (int i = 0; i < a[n]; i++) {
		k2[i] = to_str(i);
	}
	for (int i = 0; i < a[n]; i++) {
		for (int j = 0; j < a[n]; j++) {
			for (int k = 0; k < n; k++) {
				if (k2[i][k] == k2[j][k]) {
					c[i][j] += w[k];
				}
			}
		}
	}
	for (int i = 0; i < a[n]; i++) {
		for (int j = 0; j < a[n]; j++) {
			d[i][c[i][j]] += k[j];
		}
	}
	for (int i = 0; i < a[n]; i++) {
		for (int j = 0; j < 2000; j++) {
			if (j == 0) {
				e[i][j] = d[i][j];
			} else {
				e[i][j] = e[i][j-1] + d[i][j];
			}
		}
	}
	for (int i = 0; i < q; i++) {
		string temp_s;
		int temp_i;
		cin >> temp_s >> temp_i;
		int temp = to_num(temp_s);
		cout << e[temp][temp_i] << endl;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int n, m, q, w[102], k[5000], a[20], c[5000][5000];
string p, k2[5000];

int to_num(string p) {
	int num = 0;
	for (int j = 1; j <= p.length(); j++) {
		num += (p[j-1] - '0') * a[p.length() - j];
	}
	return num;
}

string to_str(int b) {
	string temp = {};
	for (int i = n - 1; i >= 0; i--){
		if (b >= a[i]) {
			temp.push_back('1');
			b -= a[i];
		} else {
			temp.push_back('0');
		}
	}
	return temp;
}

int comp(string temp_s, int temp_i) {
	int ans = 0;
	int temp = to_num(temp_s);
	for (int i = 0; i < a[n]; i++) {
		if (k[i] > 0) {
			if (temp >= i) {
				if (c[i][temp] <= temp_i) {
					ans += k[i];
				}
			} else {
				if (c[temp][i] <= temp_i) {
					ans += k[i];
				}
			}
		}
	}
	return ans;
}

int main() {
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}
	a[0] = 1;
	for (int i = 1; i < 13; i++) {
		a[i] = a[i-1] * 2;
	}
	for (int i = 0; i < m; i++) {
		cin >> p;
		k[to_num(p)]++;
	}
	for (int i = 0; i < a[n]; i++) {
		k2[i] = to_str(i);
	}
	for (int i = 0; i < a[n]; i++) {
		for (int j = i; j < a[n]; j++) {
			for (int k = 0; k < n; k++) {
				if (k2[i][k] == k2[j][k]) {
					c[i][j] += w[k];
				}
			}
		}
	}

	for (int i = 0; i < q; i++) {
		string temp_s;
		int temp_i;
		cin >> temp_s >> temp_i;
		cout << comp(temp_s, temp_i) << endl;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int n, m, q, w[102], k[5000], a[20];
string p, k2[5000];

int to_num(string p) {
	int num = 0;
	for (int j = 1; j <= p.length(); j++) {
		num += (p[j-1] - '0') * a[p.length() - j];
	}
	return num;
}

string to_str(int b) {
	string temp = {};
	for (int i = n - 1; i >= 0; i--){
		if (b >= a[i]) {
			temp.push_back('1');
			b -= a[i];
		} else {
			temp.push_back('0');
		}
	}
	return temp;
}

int comp(string temp_s, int temp_i) {
	int ans = 0;
	for (int i = 0; i < a[n]; i++) {
		int value = 0;
		if (k[i] > 0) {
			for (int j = 0; j < n; j++) {
				if (k2[i][j] == temp_s[j]) {
					value += w[j];
				}
			}
			if (value <= temp_i) {
				ans += k[i];
			}
		}
	}
	return ans;
}

int main() {
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}
	a[0] = 1;
	for (int i = 1; i < 13; i++) {
		a[i] = a[i-1] * 2;
	}
	for (int i = 0; i < m; i++) {
		cin >> p;
		k[to_num(p)]++;
	}
	for (int i = 0; i < a[n]; i++) {
		k2[i] = to_str(i);
	}

	for (int i = 0; i < q; i++) {
		string temp_s;
		int temp_i;
		cin >> temp_s >> temp_i;
		cout << comp(temp_s, temp_i) << endl;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int n, m, q, w[102], k[5000], a[20], c[5000][5000], d[5000][2000], e[5000][2000];
string k2[5000];
char p[20];

int to_num(string p) {
	int num = 0;
	for (int j = 1; j <= p.length(); j++) {
		num += (p[j-1] - '0') * a[p.length() - j];
	}
	return num;
}

string to_str(int b) {
	string temp = {};
	for (int i = n - 1; i >= 0; i--){
		if (b >= a[i]) {
			temp.push_back('1');
			b -= a[i];
		} else {
			temp.push_back('0');
		}
	}
	return temp;
}

int main() {
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}
	a[0] = 1;
	for (int i = 1; i < 13; i++) {
		a[i] = a[i-1] * 2;
	}
	for (int i = 0; i < m; i++) {
		scanf("%s", p);
		string t = p;
		k[to_num(t)]++;
	}
	for (int i = 0; i < a[n]; i++) {
		k2[i] = to_str(i);
	}
	for (int i = 0; i < a[n]; i++) {
		for (int j = i; j < a[n]; j++) {
			for (int k = 0; k < n; k++) {
				if (k2[i][k] == k2[j][k]) {
					c[i][j] += w[k];
				}
			}
		}
	}
	for (int i = 0; i < a[n]; i++) {
		for (int j = 0; j < a[n]; j++) {
			if (i > j) {
				d[i][c[j][i]] += k[j];
			} else {
				d[i][c[i][j]] += k[j];
			}
		}
	}
	for (int i = 0; i < a[n]; i++) {
		for (int j = 0; j < 2000; j++) {
			if (j == 0) {
				e[i][j] = d[i][j];
			} else {
				e[i][j] = e[i][j-1] + d[i][j];
			}
		}
	}
	for (int i = 0; i < q; i++) {
		string temp_s;
		int temp_i;
		scanf("%s %d", p, &temp_i);
		temp_s = p;
		int temp = to_num(temp_s);
		printf("%d\n", e[temp][temp_i]);
	}
	return 0;
}


/*
    Nishant Singh
    nishant.ns19
*/
#include <bits/stdc++.h>
#include <functional>
#include <iostream>

// ******** Big Integer ********
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #define ll1024  int1024_t
// ******** Big Integer ********

// ******** Using PBDS ********
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// ******** Using PBDS ********

using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vll vector<ll>
#define vec(x) vector<x>
#define setcount(x) __builtin_popcountll(x)
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define REV(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define in insert
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
#define pq priority_queue
#define ffl fflush(stdout)
#define mset multiset
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define ub upper_bound
#define lb lower_bound
ll const mod=1e9 + 7;
ll const inf=2e18;

// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag,
//              tree_order_statistics_node_update>
//                 os;
// ******** Using PBDS ********

inline ll add(ll a,ll b)
{
    return (a%mod + b%mod + mod)%mod;
}

inline ll mul(ll a,ll b)
{
    return (a%mod * b%mod + mod)%mod;
}

inline ll sub(ll a,ll b)
{
    return (a%mod - b%mod + mod)%mod;
}

ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll modexp(ll x, ll n){
    if(n==0){
        return 1;
    }
    else if(n&1){
        return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
    }
    else{
        return (modexp((x*x)%mod, n/2)%mod);
    }
}

ll modinv(ll n)
{
    return modexp(n,mod-2);
}

// ******** GLOBAL VARIABLES ********
ll const MAX=300001;
ll n,m;
string s[MAX];
ll w[101];
unordered_map<ll,ll> m1;
ll dp[1024][101];
ll km=1LL<<(12);
// ******** GLOBAL VARIABLES ********
int binaryToDecimal(string n)
{
    string num = n;
    int dec_value = 0;

    // Initializing base value to 1, i.e 2^0
    int base = 1;

    int len = num.length();
    for (int i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }

    return dec_value;
}

void fun(ll num)
{
    for(auto it:m1)
    {
        ll x=(num^it.f);

        ll v=0;
        REP(i,n)
        {
            if(!(x&(1<<i)))
            {
                v=v+w[n-i-1];
            }
        }
        dp[num][v]+=it.s;

    }
    for(int i=1;i<=100;i++)
    {
        dp[num][i]+=dp[num][i-1];
    //    cout<<dp[num][i]<<" ";
    }

}

void solve(){
    init(dp,0);
    ll q;

    cin>>n>>m>>q;
    REP(i,n)
    {
        cin>>w[i];
    }
    REP(i,m)
    {
        cin>>s[i];
       // cout<<s[i]<<" "<<binaryToDecimal(s[i])<<"\n";
        m1[binaryToDecimal(s[i])]++;
    }
    // cout<<endl;
    REP(i,1024)
    {
        fun(i);
    }
    while(q--)
    {
        string t;
        ll k;
        cin>>t>>k;
       cout<<dp[binaryToDecimal(t)][k]<<endl;

    }

   }

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll T=1;
    // cin>>T;
        for(int t=1;t<=T;t++)
        {
        // cout<<"Case #"<<t<<": ";
            solve();
        }
        return 0;
    }


/*
    Nishant Singh
    nishant.ns19
*/
#include <bits/stdc++.h>
#include <functional>
#include <iostream>

// ******** Big Integer ********
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #define ll1024  int1024_t
// ******** Big Integer ********

// ******** Using PBDS ********
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// ******** Using PBDS ********

using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vll vector<ll>
#define vec(x) vector<x>
#define setcount(x) __builtin_popcountll(x)
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define REV(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define in insert
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
#define pq priority_queue
#define ffl fflush(stdout)
#define mset multiset
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define ub upper_bound
#define lb lower_bound
ll const mod=1e9 + 7;
ll const inf=2e18;

// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag,
//              tree_order_statistics_node_update>
//                 os;
// ******** Using PBDS ********

inline ll add(ll a,ll b)
{
    return (a%mod + b%mod + mod)%mod;
}

inline ll mul(ll a,ll b)
{
    return (a%mod * b%mod + mod)%mod;
}

inline ll sub(ll a,ll b)
{
    return (a%mod - b%mod + mod)%mod;
}

ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll modexp(ll x, ll n){
    if(n==0){
        return 1;
    }
    else if(n&1){
        return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
    }
    else{
        return (modexp((x*x)%mod, n/2)%mod);
    }
}

ll modinv(ll n)
{
    return modexp(n,mod-2);
}

// ******** GLOBAL VARIABLES ********
ll const MAX=500001;
ll n,m;
string s[MAX];
ll w[101];
ll m1[4096];
ll dp[4096][101];
// ******** GLOBAL VARIABLES ********
int binaryToDecimal(string st)
{
    string num = st;
    int dec_value = 0;
    int base = 1;
    int len = n;
    for (int i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }
    return dec_value;
}

void fun(ll num)
{
    REP(i,4096)
    {
        if(m1[i]>0)
        {

        ll x=(num^i);

        ll v=0;
        REP(i,n)
        {
            if(!(x&(1<<i)))
            {
                v=v+w[n-i-1];
            }
        }
        if(v<=100)
        dp[num][v]+=m1[i];

    }
}

    for(int i=1;i<=100;i++)
    {
        dp[num][i]+=dp[num][i-1];
    //    cout<<dp[num][i]<<" ";
    }

}

void solve(){
    init(m1,0);
    init(dp,0);
    ll q;
    cin>>n>>m>>q;
    REP(i,n)
    {
        cin>>w[i];
    }
    REP(i,m)
    {
        cin>>s[i];
        m1[binaryToDecimal(s[i])]++;
    }

    bool vis[4096];
    init(vis,false);
    while(q--)
    {
        string t;
        ll k;
        cin>>t>>k;
        ll tn=binaryToDecimal(t);
        if(!vis[tn])
        {
            fun(tn);
            vis[tn]=true;
        }

       cout<<dp[tn][k]<<"\n";
    }
   }

    int main()
    {

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll T=1;

    // cin>>T;
        for(int t=1;t<=T;t++)
        {
        // cout<<"Case #"<<t<<": ";
            solve();
        }
        return 0;
    }


/*
    Nishant Singh
    nishant.ns19
*/
#include <bits/stdc++.h>
#include <functional>
#include <iostream>

// ******** Big Integer ********
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #define ll1024  int1024_t
// ******** Big Integer ********

// ******** Using PBDS ********
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// ******** Using PBDS ********

using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vll vector<ll>
#define vec(x) vector<x>
#define setcount(x) __builtin_popcountll(x)
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define REV(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define in insert
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
#define pq priority_queue
#define ffl fflush(stdout)
#define mset multiset
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define ub upper_bound
#define lb lower_bound
ll const mod=1e9 + 7;
ll const inf=2e18;

// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag,
//              tree_order_statistics_node_update>
//                 os;
// ******** Using PBDS ********

inline ll add(ll a,ll b)
{
    return (a%mod + b%mod + mod)%mod;
}

inline ll mul(ll a,ll b)
{
    return (a%mod * b%mod + mod)%mod;
}

inline ll sub(ll a,ll b)
{
    return (a%mod - b%mod + mod)%mod;
}

ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll modexp(ll x, ll n){
    if(n==0){
        return 1;
    }
    else if(n&1){
        return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
    }
    else{
        return (modexp((x*x)%mod, n/2)%mod);
    }
}

ll modinv(ll n)
{
    return modexp(n,mod-2);
}

// ******** GLOBAL VARIABLES ********
ll const MAX=500001;
ll n,m;
string s[MAX];
ll w[101];
map<ll,ll> m1;
ll dp[1024][101];
// ******** GLOBAL VARIABLES ********
int binaryToDecimal(string st)
{
    string num = st;
    int dec_value = 0;
    int base = 1;
    int len = n;
    for (int i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }
    return dec_value;
}

void fun(ll num)
{
    for(auto it:m1)
    {
        ll x=(num^it.f);

        ll v=0;
        REP(i,n)
        {
            if(!(x&(1<<i)))
            {
                v=v+w[n-i-1];
            }
        }
        dp[num][v]+=it.s;

    }
    for(int i=1;i<=100;i++)
    {
        dp[num][i]+=dp[num][i-1];
    //    cout<<dp[num][i]<<" ";
    }
}

void solve(){
    init(dp,0);
    ll q;
    cin>>n>>m>>q;
    REP(i,n)
    {
        cin>>w[i];
    }
    REP(i,m)
    {
        cin>>s[i];
        m1[binaryToDecimal(s[i])]++;
    }

    bool vis[1024];
    init(vis,false);
    while(q--)
    {
        string t;
        ll k;
        cin>>t>>k;
        ll tn=binaryToDecimal(t);
        if(!vis[tn])
        {
            fun(tn);
            vis[tn]=true;
        }

       cout<<dp[tn][k]<<"\n";
    }

   }

    int main()
    {

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll T=1;

    // cin>>T;
        for(int t=1;t<=T;t++)
        {
        // cout<<"Case #"<<t<<": ";
            solve();
        }
        return 0;
    }


/*
    Nishant Singh
    nishant.ns19
*/
#include <bits/stdc++.h>
#include <functional>
#include <iostream>

// ******** Big Integer ********
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #define ll1024  int1024_t
// ******** Big Integer ********

// ******** Using PBDS ********
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// ******** Using PBDS ********

using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vll vector<ll>
#define vec(x) vector<x>
#define setcount(x) __builtin_popcountll(x)
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define REV(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define in insert
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
#define pq priority_queue
#define ffl fflush(stdout)
#define mset multiset
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define ub upper_bound
#define lb lower_bound
ll const mod=1e9 + 7;
ll const inf=2e18;

// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag,
//              tree_order_statistics_node_update>
//                 os;
// ******** Using PBDS ********

inline ll add(ll a,ll b)
{
    return (a%mod + b%mod + mod)%mod;
}

inline ll mul(ll a,ll b)
{
    return (a%mod * b%mod + mod)%mod;
}

inline ll sub(ll a,ll b)
{
    return (a%mod - b%mod + mod)%mod;
}

ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll modexp(ll x, ll n){
    if(n==0){
        return 1;
    }
    else if(n&1){
        return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
    }
    else{
        return (modexp((x*x)%mod, n/2)%mod);
    }
}

ll modinv(ll n)
{
    return modexp(n,mod-2);
}

// ******** GLOBAL VARIABLES ********
ll const MAX=500001;
ll n,m;
string s[MAX];
ll w[101];
unordered_map<ll,ll> m1;
ll dp[1024][101];
ll km=1LL<<(12);
// ******** GLOBAL VARIABLES ********
int binaryToDecimal(string st)
{
    string num = st;
    int dec_value = 0;

    // Initializing base value to 1, i.e 2^0
    int base = 1;

    int len = n;
    for (int i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }
    return dec_value;
}

void fun(ll num)
{
    for(auto it:m1)
    {
        ll x=(num^it.f);

        ll v=0;
        REP(i,n)
        {
            if(!(x&(1<<i)))
            {
                v=v+w[n-i-1];
            }
        }
        dp[num][v]+=it.s;

    }
    for(int i=1;i<=100;i++)
    {
        dp[num][i]+=dp[num][i-1];
    //    cout<<dp[num][i]<<" ";
    }

}

void solve(){
    init(dp,0);
    ll q;

    cin>>n>>m>>q;
    REP(i,n)
    {
        cin>>w[i];
    }
    REP(i,m)
    {
        cin>>s[i];
       // cout<<s[i]<<" "<<binaryToDecimal(s[i])<<"\n";
        m1[binaryToDecimal(s[i])]++;
    }
    // cout<<endl;
    bool vis[1024];
    init(vis,false);
    while(q--)
    {
        string t;
        ll k;
        cin>>t>>k;
        ll tn=binaryToDecimal(t);
        if(!vis[tn])
        {
            fun(tn);
            vis[tn]=true;
        }

       cout<<dp[tn][k]<<"\n";
    }
   }

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll T=1;
    // cin>>T;
        for(int t=1;t<=T;t++)
        {
        // cout<<"Case #"<<t<<": ";
            solve();
        }
        return 0;
    }


/*
    Nishant Singh
    nishant.ns19
*/
#include <bits/stdc++.h>
#include <functional>
#include <iostream>

// ******** Big Integer ********
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #define ll1024  int1024_t
// ******** Big Integer ********

// ******** Using PBDS ********
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// ******** Using PBDS ********

using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vll vector<ll>
#define vec(x) vector<x>
#define setcount(x) __builtin_popcountll(x)
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define REV(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define in insert
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
#define pq priority_queue
#define ffl fflush(stdout)
#define mset multiset
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define ub upper_bound
#define lb lower_bound
ll const mod=1e9 + 7;
ll const inf=2e18;

// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag,
//              tree_order_statistics_node_update>
//                 os;
// ******** Using PBDS ********

inline ll add(ll a,ll b)
{
    return (a%mod + b%mod + mod)%mod;
}

inline ll mul(ll a,ll b)
{
    return (a%mod * b%mod + mod)%mod;
}

inline ll sub(ll a,ll b)
{
    return (a%mod - b%mod + mod)%mod;
}

ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll modexp(ll x, ll n){
    if(n==0){
        return 1;
    }
    else if(n&1){
        return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
    }
    else{
        return (modexp((x*x)%mod, n/2)%mod);
    }
}

ll modinv(ll n)
{
    return modexp(n,mod-2);
}

// ******** GLOBAL VARIABLES ********
ll const MAX=500001;
ll n,m;
string s[MAX];
ll w[101];
ll m1[4096];
ll dp[4096][101];
// ******** GLOBAL VARIABLES ********
int binaryToDecimal(string st)
{
    string num = st;
    int dec_value = 0;
    int base = 1;
    int len = n;
    for (int i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }
    return dec_value;
}

void fun(ll num)
{
    REP(i,4096)
    {
        if(m1[i]>0)
        {

        ll x=(num^i);

        ll v=0;
        REP(i,n)
        {
            if(!(x&(1<<i)))
            {
                v=v+w[n-i-1];
            }
        }

        dp[num][v]+=m1[i];

    }
}

    for(int i=1;i<=100;i++)
    {
        dp[num][i]+=dp[num][i-1];
    //    cout<<dp[num][i]<<" ";
    }

}

void solve(){
    init(m1,0);
    init(dp,0);
    ll q;
    cin>>n>>m>>q;
    REP(i,n)
    {
        cin>>w[i];
    }
    REP(i,m)
    {
        cin>>s[i];
        m1[binaryToDecimal(s[i])]++;
    }

    bool vis[4096];
    init(vis,false);
    while(q--)
    {
        string t;
        ll k;
        cin>>t>>k;
        ll tn=binaryToDecimal(t);
        if(!vis[tn])
        {
            fun(tn);
            vis[tn]=true;
        }

       cout<<dp[tn][k]<<"\n";
    }
   }

    int main()
    {

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll T=1;

    // cin>>T;
        for(int t=1;t<=T;t++)
        {
        // cout<<"Case #"<<t<<": ";
            solve();
        }
        return 0;
    }


/*
    Nishant Singh
    nishant.ns19
*/
#include <bits/stdc++.h>
#include <functional>
#include <iostream>

// ******** Big Integer ********
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #define ll1024  int1024_t
// ******** Big Integer ********

// ******** Using PBDS ********
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// ******** Using PBDS ********

using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vll vector<ll>
#define vec(x) vector<x>
#define setcount(x) __builtin_popcountll(x)
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define REV(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define in insert
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
#define pq priority_queue
#define ffl fflush(stdout)
#define mset multiset
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define ub upper_bound
#define lb lower_bound
ll const mod=1e9 + 7;
ll const inf=2e18;

// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag,
//              tree_order_statistics_node_update>
//                 os;
// ******** Using PBDS ********

inline ll add(ll a,ll b)
{
    return (a%mod + b%mod + mod)%mod;
}

inline ll mul(ll a,ll b)
{
    return (a%mod * b%mod + mod)%mod;
}

inline ll sub(ll a,ll b)
{
    return (a%mod - b%mod + mod)%mod;
}

ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll modexp(ll x, ll n){
    if(n==0){
        return 1;
    }
    else if(n&1){
        return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
    }
    else{
        return (modexp((x*x)%mod, n/2)%mod);
    }
}

ll modinv(ll n)
{
    return modexp(n,mod-2);
}

// ******** GLOBAL VARIABLES ********
ll const MAX=500001;
ll n,m;
string s[MAX];
ll w[101];
unordered_map<ll,ll> m1;
ll dp[1024][101];
ll km=1LL<<(12);
// ******** GLOBAL VARIABLES ********
int binaryToDecimal(string n)
{
    string num = n;
    int dec_value = 0;

    // Initializing base value to 1, i.e 2^0
    int base = 1;

    int len = num.length();
    for (int i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }

    return dec_value;
}

void fun(ll num)
{
    for(auto it:m1)
    {
        ll x=(num^it.f);

        ll v=0;
        REP(i,n)
        {
            if(!(x&(1<<i)))
            {
                v=v+w[n-i-1];
            }
        }
        dp[num][v]+=it.s;

    }
    for(int i=1;i<=100;i++)
    {
        dp[num][i]+=dp[num][i-1];
    //    cout<<dp[num][i]<<" ";
    }

}

void solve(){
    init(dp,0);
    ll q;

    cin>>n>>m>>q;
    REP(i,n)
    {
        cin>>w[i];
    }
    REP(i,m)
    {
        cin>>s[i];
       // cout<<s[i]<<" "<<binaryToDecimal(s[i])<<"\n";
        m1[binaryToDecimal(s[i])]++;
    }
    // cout<<endl;
    REP(i,1024)
    {
        fun(i);
    }
    while(q--)
    {
        string t;
        ll k;
        cin>>t>>k;
       cout<<dp[binaryToDecimal(t)][k]<<endl;

    }

   }

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll T=1;
    // cin>>T;
        for(int t=1;t<=T;t++)
        {
        // cout<<"Case #"<<t<<": ";
            solve();
        }
        return 0;
    }


#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma GCC optimize("O3")
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int a[13], kl[4100], sum[4100], ans[4100][101];
vector<pii> vc[4100];
bitset<13> b;
string st, ex;
unordered_map<string, int> ump;

int main()
{
    fast_io;
    int n, m, q, i, j, k, x;
    cin >> n >> m >> q;
    for (i = 1; i <= n; i++) cin >> a[i], ex += "0";
    for (i = 0; i < (1 << n); i++)
    {
        st = ex;
        b = i;
        for (j = 0; j < n; j++)
            b[j] ? st[n - j - 1] = '1' : sum[i] += a[n - j];
        ump[st] = i;
    }
    while (m--)
    {
        cin >> st;
        kl[ump[st]]++;
    }
    for (i = 0; i < (1 << n); i++)
    {
        for (j = 0; j < (1 << n); j++)
            if (kl[j]) vc[i].pb({sum[i ^ j], kl[j]});
        sort(all(vc[i]));
        x = k = 0;
        for (j = 0; j <= 100; j++)
        {
            while (x < vc[i].size() && vc[i][x].first <= j) k += vc[i][x].second, x++;
            ans[i][j] = k;
        }
    }
    while (q--)
    {
        cin >> st >> k;
        cout << ans[ump[st]][k] << '\n';
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int a[13], kl[4100], sum[4100], ans[4100][101];
vector<pii> vc[4100];
string st, ex;
unordered_map<string, int> ump;

int main()
{
    fast_io;
    int n, m, q, i, j, k, x;
    cin >> n >> m >> q;
    for (i = 1; i <= n; i++) cin >> a[i], ex += "0";
    for (i = 0; i < (1 << n); i++)
    {
        st = ex;
        for (j = 0; j < n; j++)
            (i & (1 << j)) ? st[n - j - 1] = '1' : sum[i] += a[n - j];
        ump[st] = i;
    }
    while (m--)
    {
        cin >> st;
        kl[ump[st]]++;
    }
    for (i = 0; i < (1 << n); i++)
    {
        for (j = 0; j < (1 << n); j++)
            if (kl[j]) vc[i].pb({sum[i ^ j], kl[j]});
        sort(all(vc[i]));
        x = k = 0;
        for (j = 0; j <= 100; j++)
        {
            while (x < vc[i].size() && vc[i][x].first <= j) k += vc[i][x].second, x++;
            ans[i][j] = k;
        }
    }
    while (q--)
    {
        cin >> st >> k;
        cout << ans[ump[st]][k] << '\n';
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int a[12], kl[4100];
vector<pii> vc[4100];
bitset<13> b1, b2;

int main()
{
    fast_io;
    int n, m, q, i, j, k, s, l, r, md;
    string str;
    cin >> n >> m >> q;
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = 1; i <= m; i++)
    {
        cin >> str;
        for (j = 0, s = 0; j < n; j++)
            if (str[j] == '1') s += pow(2, n - j - 1);
        kl[s]++;
    }
    for (i = 0; i < (1 << n); i++)
    {
        b1 = i;
        for (j = 0; j < (1 << n); j++)
        {
            if (!kl[j]) continue;
            b2 = j;
            s = 0;
            for (k = 0; k < n; k++)
                if (b1[k] == b2[k]) s += a[n - k - 1];
            vc[i].pb({s, kl[j]});
        }
        sort(all(vc[i]));
        for (j = 1; j < vc[i].size(); j++) vc[i][j].second += vc[i][j - 1].second;
    }
    for (i = 1; i <= q; i++)
    {
        cin >> str >> k;
        for (j = 0, s = 0; j < n; j++)
            if (str[j] == '1') s += pow(2, n - j - 1);
        l = 0, r = vc[s].size() - 1;
        while (r > l)
        {
            md = (l + r) / 2 + 1;
            if (vc[s][md].first > k) r = md - 1;
            else l = md;
        }
        if (vc[s][l].first > k) cout << 0;
        else cout << vc[s][l].second;
        cout << '\n';
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int a[12], kl[4100], st[13];
vector<pii> vc[4100];
bitset<13> b;
unordered_map<string, int> ump;

int main()
{
    fast_io;
    int n, m, q, i, j, k, s, l, r, md;
    string str;
    cin >> n >> m >> q;
    for (i = 0; i < n; i++) cin >> a[i];
    st[0] = 1;
    for (i = 1; i <= 12; i++) st[i] = st[i - 1] * 2;
    for (i = 0; i < (1 << n); i++)
    {
        string st;
        b = i;
        for (j = 0; j < n; j++) st += b[j] + '0';
        reverse(all(st));
        ump[st] = i;
    }
    for (i = 1; i <= m; i++)
    {
        cin >> str;
        kl[ump[str]]++;
    }
    for (i = 0; i < (1 << n); i++)
    {
        for (j = 0; j < (1 << n); j++)
        {
            if (!kl[j]) continue;
            b = i ^ j;
            s = 0;
            for (k = 0; k < n; k++)
                if (!b[k]) s += a[n - k - 1];
            vc[i].pb({s, kl[j]});
        }
        sort(all(vc[i]));
        for (j = 1; j < vc[i].size(); j++) vc[i][j].second += vc[i][j - 1].second;
    }
    for (i = 1; i <= q; i++)
    {
        cin >> str >> k;
        s = ump[str];
        l = 0, r = vc[s].size() - 1;
        while (r > l)
        {
            md = (l + r) / 2 + 1;
            if (vc[s][md].first > k) r = md - 1;
            else l = md;
        }
        if (vc[s][l].first > k) cout << 0;
        else cout << vc[s][l].second;
        cout << '\n';
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int a[13], kl[4100], sum[4100], ans[4100][101];
vector<pii> vc[4100];
bitset<13> b;
string st;
unordered_map<string, int> ump;

int main()
{
    fast_io;
    int n, m, q, i, j, k, x;
    cin >> n >> m >> q;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 0; i < (1 << n); i++)
    {
        st = "";
        b = i;
        for (j = 0, x = 0; j < n; j++)
        {
            st += b[j] + '0';
            if (!b[j]) x += a[n - j];
        }
        sum[i] = x;
        reverse(all(st));
        ump[st] = i;
    }
    while (m--)
    {
        cin >> st;
        kl[ump[st]]++;
    }
    for (i = 0; i < (1 << n); i++)
    {
        for (j = 0; j < (1 << n); j++)
            if (kl[j]) vc[i].pb({sum[i ^ j], kl[j]});
        sort(all(vc[i]));
        x = k = 0;
        for (j = 0; j <= 100; j++)
        {
            while (x < vc[i].size() && vc[i][x].first <= j) k += vc[i][x].second, x++;
            ans[i][j] = k;
        }
    }
    while (q--)
    {
        cin >> st >> k;
        cout << ans[ump[st]][k] << '\n';
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int a[12], kl[4100];
vector<int> vc[4100];
bitset<13> b1, b2;

int main()
{
    fast_io;
    int n, m, q, i, j, k, s, l, r, md;
    string str;
    cin >> n >> m >> q;
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = 1; i <= m; i++)
    {
        cin >> str;
        for (j = 0, s = 0; j < n; j++)
            if (str[j] == '1') s += pow(2, n - j - 1);
        kl[s]++;
    }
    for (i = 0; i < (1 << n); i++)
    {
        b1 = i;
        for (j = 0; j < (1 << n); j++)
        {
            if (!kl[j]) continue;
            b2 = j;
            s = 0;
            for (k = 0; k < n; k++)
                if (b1[k] == b2[k]) s += a[n - k - 1];
            for (k = 0; k < kl[j]; k++) vc[i].pb(s);
        }
        sort(all(vc[i]));
    }
    for (i = 1; i <= q; i++)
    {
        cin >> str >> k;
        for (j = 0, s = 0; j < n; j++)
            if (str[j] == '1') s += pow(2, n - j - 1);
        l = 0, r = vc[s].size() - 1;
        while (r > l)
        {
            md = (l + r) / 2 + 1;
            if (vc[s][md] > k) r = md - 1;
            else l = md;
        }
        if (vc[s][l] > k) cout << 0;
        else cout << l + 1;
        cout << '\n';
    }
    return 0;
}


// Igorjan94, template version from 13 October 2017. C++17 version {{{
//{
#include <bits/stdc++.h>

using namespace std;

#define FILENAME "input"

#define FOR(i, m, n) for (int i = m; i <  (int) (n); ++i)
#define ROF(i, m, n) for (int i = m; i >= (int) (n); --i)
#define forn(i, n)   for (int i = 0; i < (int) (n); ++i)
#define  fori1(n)    for (int i = 1; i < (int) (n); ++i)
#define  forj1(n)    for (int j = 1; j < (int) (n); ++j)
#define   fori(n)    for (int i = 0; i < (int) (n); ++i)
#define   forj(n)    for (int j = 0; j < (int) (n); ++j)

typedef vector<long long> vll;
typedef  pair<int, int>   pii;
typedef  valarray<int>    va;
typedef   vector<int>     vi;
typedef    long long      ll;

#define    pb    push_back
#define whole(a) a.begin(), a.end()
#define   next   next__
#define   prev   prev__
#define  count   count__

#define ints(a...)  int a; readln(a)
#define wr(args...) err(#args, args)

#define ttt12i template<class T1, class T2> inline
#define  tthti template<class H, class...T> inline
#define  ttta  template<class... Args> inline
#define  ttti  template<class T> inline

const int MOD = 1000000007;
const int INTMAX = numeric_limits<int>::max();
const ll LLMAX = numeric_limits<ll>::max();

void writeln(){cout<<"\n";}ttti void print(T a);ttti void priws(T a);ttti void read(T& a);
ttta void readln(Args&... args){(read(args),...);}tthti void writeln(H h,T...t){priws(h);(print(t),...);writeln();}
ttti void writeln_range(T f,T s){if(f!=s)for(auto i=f;i!=s;++i)writeln(*i);}
vector<string>split(string&s,string d){vector<string> v;size_t p=0;while((p=s.find(d))!=string::npos)v.pb(s.substr(0,p)),s.erase(0,p+d.length());v.pb(s);return v;}
ttta void err(string v,Args...args){auto vv=split(v,", ");auto it=vv.begin();(writeln(*it++,"=",args),...);}

//Igorjan
//}}}

int dp[4096][4096];
int mp[4096];

void run()
{
    int n, m, q;
    scanf("%d%d%d", &n, &m, &q);
    int M = 1 << n;
    vector<int> w(n);
    fori(n) scanf("%d", &w[i]);
    char s[n];
    auto ggg = [&]() {
        int ans = 0;
        fori(n)
            if (s[n - 1 - i] == '1')
                ans += 1 << i;
        return ans;
    };

    fori(M)
        FOR(j, i, M)
        {
            int sm = 0;
            FOR(k, 0, n)
                sm += ((i & (1 << k)) == (j & (1 << k))) * w[n - 1 - k];
            dp[i][j] = sm;
        }

    forj(m)
    {
        scanf("%s", s);
        mp[ggg()]++;
    }
    forj(q)
    {
        int k;
        scanf("%s%d", s, &k);
        int x = ggg();
        int ans = 0;
        fori(M)
            ans += mp[i] * (dp[min(x, i)][max(x, i)] <= k);
        printf("%d\n", ans);
    }
}

//{{{
int main()
{
#ifndef ONLINE_JUDGE
    double time = clock();
#endif
 //   ios_base::sync_with_stdio(false);
//    freopen(FILENAME".in", "r", stdin);
//    freopen(FILENAME".out", "w", stdout);
    run();
#ifndef ONLINE_JUDGE
    writeln("execution time =", (clock() - time) / CLOCKS_PER_SEC);
#endif
    return 0;
}

#define a _a
#define n _n
ttti   ostream&operator<<(ostream&os,vector<T>&a);
ttt12i istream&operator>>(istream&is,pair<T1,T2>&a){return is>>a.first>>a.second;}
ttt12i ostream&operator<<(ostream&os,pair<T1,T2>&a){return os<<a.first<<" "<<a.second;}
ttti   ostream&operator<<(ostream&os,vector<T>&a){if(a.size())os<<a[0];else os<<"\n";fori1(a.size())os<<"\n "[is_fundamental<T>::value]<<a[i];return os;}
ttti   ostream&operator<<(ostream&os,valarray<T>&a){if(a.size())os<<a[0];else os<<"\n";fori1(a.size())os<<"\n "[is_fundamental<T>::value]<<a[i];return os;}
ttti   istream&operator>>(istream&is,vector<T>&a){fori(a.size())is>>a[i];return is;}
ttti   istream&operator>>(istream&is,valarray<T>&a){fori(a.size())is>>a[i];return is;}
ttti void print(T a){cout<<" "<<a;}
ttti void priws(T a){cout<<a;}
ttti void read(T& a){cin>>a;} //}}}


// Igorjan94, template version from 13 October 2017. C++17 version {{{
//{
#include <bits/stdc++.h>

using namespace std;

#define FILENAME "input"

#define FOR(i, m, n) for (int i = m; i <  (int) (n); ++i)
#define ROF(i, m, n) for (int i = m; i >= (int) (n); --i)
#define forn(i, n)   for (int i = 0; i < (int) (n); ++i)
#define  fori1(n)    for (int i = 1; i < (int) (n); ++i)
#define  forj1(n)    for (int j = 1; j < (int) (n); ++j)
#define   fori(n)    for (int i = 0; i < (int) (n); ++i)
#define   forj(n)    for (int j = 0; j < (int) (n); ++j)

typedef vector<long long> vll;
typedef  pair<int, int>   pii;
typedef  valarray<int>    va;
typedef   vector<int>     vi;
typedef    long long      ll;

#define    pb    push_back
#define whole(a) a.begin(), a.end()
#define   next   next__
#define   prev   prev__
#define  count   count__

#define ints(a...)  int a; readln(a)
#define wr(args...) err(#args, args)

#define ttt12i template<class T1, class T2> inline
#define  tthti template<class H, class...T> inline
#define  ttta  template<class... Args> inline
#define  ttti  template<class T> inline

const int MOD = 1000000007;
const int INTMAX = numeric_limits<int>::max();
const ll LLMAX = numeric_limits<ll>::max();

void writeln(){cout<<"\n";}ttti void print(T a);ttti void priws(T a);ttti void read(T& a);
ttta void readln(Args&... args){(read(args),...);}tthti void writeln(H h,T...t){priws(h);(print(t),...);writeln();}
ttti void writeln_range(T f,T s){if(f!=s)for(auto i=f;i!=s;++i)writeln(*i);}
vector<string>split(string&s,string d){vector<string> v;size_t p=0;while((p=s.find(d))!=string::npos)v.pb(s.substr(0,p)),s.erase(0,p+d.length());v.pb(s);return v;}
ttta void err(string v,Args...args){auto vv=split(v,", ");auto it=vv.begin();(writeln(*it++,"=",args),...);}

//Igorjan
//}}}

int dp[4096][4096];

void run()
{
    int n, m, q;
    scanf("%d%d%d", &n, &m, &q);
    int M = 1 << n;
    vector<int> w(n);
    fori(n) scanf("%d", &w[i]);
    map<int, int> mp;

    auto ggg = [&](string_view s) {
        int ans = 0;
        fori(n)
            if (s[n - 1 - i] == '1')
                ans += 1 << i;
        return ans;
    };

    fori(M)
        forj(M)
        {
            int sm = 0;
            FOR(k, 0, n)
                sm += ((i & (1 << k)) == (j & (1 << k))) * w[n - 1 - k];
            dp[i][j] = sm;
        }
    char s[n];
    forj(m)
    {
        scanf("%s", s);
        mp[ggg(s)]++;
    }
    forj(q)
    {
        int k;
        scanf("%s%d", s, &k);
        int x = ggg(s);
        int ans = 0;
        fori(M)
            ans += mp[i] * (dp[x][i] <= k);
        printf("%d\n", ans);
    }
}

//{{{
int main()
{
#ifndef ONLINE_JUDGE
    double time = clock();
#endif
 //   ios_base::sync_with_stdio(false);
//    freopen(FILENAME".in", "r", stdin);
//    freopen(FILENAME".out", "w", stdout);
    run();
#ifndef ONLINE_JUDGE
    writeln("execution time =", (clock() - time) / CLOCKS_PER_SEC);
#endif
    return 0;
}

#define a _a
#define n _n
ttti   ostream&operator<<(ostream&os,vector<T>&a);
ttt12i istream&operator>>(istream&is,pair<T1,T2>&a){return is>>a.first>>a.second;}
ttt12i ostream&operator<<(ostream&os,pair<T1,T2>&a){return os<<a.first<<" "<<a.second;}
ttti   ostream&operator<<(ostream&os,vector<T>&a){if(a.size())os<<a[0];else os<<"\n";fori1(a.size())os<<"\n "[is_fundamental<T>::value]<<a[i];return os;}
ttti   ostream&operator<<(ostream&os,valarray<T>&a){if(a.size())os<<a[0];else os<<"\n";fori1(a.size())os<<"\n "[is_fundamental<T>::value]<<a[i];return os;}
ttti   istream&operator>>(istream&is,vector<T>&a){fori(a.size())is>>a[i];return is;}
ttti   istream&operator>>(istream&is,valarray<T>&a){fori(a.size())is>>a[i];return is;}
ttti void print(T a){cout<<" "<<a;}
ttti void priws(T a){cout<<a;}
ttti void read(T& a){cin>>a;} //}}}


// Igorjan94, template version from 13 October 2017. C++17 version {{{
//{
#include <bits/stdc++.h>

using namespace std;

#define FILENAME "input"

#define FOR(i, m, n) for (int i = m; i <  (int) (n); ++i)
#define ROF(i, m, n) for (int i = m; i >= (int) (n); --i)
#define forn(i, n)   for (int i = 0; i < (int) (n); ++i)
#define  fori1(n)    for (int i = 1; i < (int) (n); ++i)
#define  forj1(n)    for (int j = 1; j < (int) (n); ++j)
#define   fori(n)    for (int i = 0; i < (int) (n); ++i)
#define   forj(n)    for (int j = 0; j < (int) (n); ++j)

typedef vector<long long> vll;
typedef  pair<int, int>   pii;
typedef  valarray<int>    va;
typedef   vector<int>     vi;
typedef    long long      ll;

#define    pb    push_back
#define whole(a) a.begin(), a.end()
#define   next   next__
#define   prev   prev__
#define  count   count__

#define ints(a...)  int a; readln(a)
#define wr(args...) err(#args, args)

#define ttt12i template<class T1, class T2> inline
#define  tthti template<class H, class...T> inline
#define  ttta  template<class... Args> inline
#define  ttti  template<class T> inline

const int MOD = 1000000007;
const int INTMAX = numeric_limits<int>::max();
const ll LLMAX = numeric_limits<ll>::max();

void writeln(){cout<<"\n";}ttti void print(T a);ttti void priws(T a);ttti void read(T& a);
ttta void readln(Args&... args){(read(args),...);}tthti void writeln(H h,T...t){priws(h);(print(t),...);writeln();}
ttti void writeln_range(T f,T s){if(f!=s)for(auto i=f;i!=s;++i)writeln(*i);}
vector<string>split(string&s,string d){vector<string> v;size_t p=0;while((p=s.find(d))!=string::npos)v.pb(s.substr(0,p)),s.erase(0,p+d.length());v.pb(s);return v;}
ttta void err(string v,Args...args){auto vv=split(v,", ");auto it=vv.begin();(writeln(*it++,"=",args),...);}

//Igorjan
//}}}

int dp[4096][4096];
int mp[4096];

void run()
{
    int n, m, q;
    scanf("%d%d%d", &n, &m, &q);
    int M = 1 << n;
    vector<int> w(n);
    fori(n) scanf("%d", &w[i]);
    char s[n];
    auto ggg = [&]() {
        int ans = 0;
        fori(n)
            if (s[n - 1 - i] == '1')
                ans += 1 << i;
        return ans;
    };

    fori(M)
        forj(M)
        {
            int sm = 0;
            FOR(k, 0, n)
                sm += ((i & (1 << k)) == (j & (1 << k))) * w[n - 1 - k];
            dp[i][j] = sm;
        }

    forj(m)
    {
        scanf("%s", s);
        mp[ggg()]++;
    }
    forj(q)
    {
        int k;
        scanf("%s%d", s, &k);
        int x = ggg();
        int ans = 0;
        fori(M)
            ans += mp[i] * (dp[x][i] <= k);
        printf("%d\n", ans);
    }
}

//{{{
int main()
{
#ifndef ONLINE_JUDGE
    double time = clock();
#endif
 //   ios_base::sync_with_stdio(false);
//    freopen(FILENAME".in", "r", stdin);
//    freopen(FILENAME".out", "w", stdout);
    run();
#ifndef ONLINE_JUDGE
    writeln("execution time =", (clock() - time) / CLOCKS_PER_SEC);
#endif
    return 0;
}

#define a _a
#define n _n
ttti   ostream&operator<<(ostream&os,vector<T>&a);
ttt12i istream&operator>>(istream&is,pair<T1,T2>&a){return is>>a.first>>a.second;}
ttt12i ostream&operator<<(ostream&os,pair<T1,T2>&a){return os<<a.first<<" "<<a.second;}
ttti   ostream&operator<<(ostream&os,vector<T>&a){if(a.size())os<<a[0];else os<<"\n";fori1(a.size())os<<"\n "[is_fundamental<T>::value]<<a[i];return os;}
ttti   ostream&operator<<(ostream&os,valarray<T>&a){if(a.size())os<<a[0];else os<<"\n";fori1(a.size())os<<"\n "[is_fundamental<T>::value]<<a[i];return os;}
ttti   istream&operator>>(istream&is,vector<T>&a){fori(a.size())is>>a[i];return is;}
ttti   istream&operator>>(istream&is,valarray<T>&a){fori(a.size())is>>a[i];return is;}
ttti void print(T a){cout<<" "<<a;}
ttti void priws(T a){cout<<a;}
ttti void read(T& a){cin>>a;} //}}}