// 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]);

    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];
int gt[4096][101];

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];
    vector<int> degs;
    fori(n + 1) degs.pb(1 << i);

    auto ggg = [&]() {
        int ans = 0;
        ROF(i, n - 1, 0)
            if (s[i] == '1')
                ans += degs[n - i - 1];
        return ans;
    };

    fori(M)
        forj(M)
        {
            int sm = 0;
            FOR(k, 0, n)
                sm += ((i & degs[k]) == (j & degs[k])) * w[n - 1 - k];
            dp[i][j] = sm;
        }
    forj(m)
    {
        scanf("%s", s);
        mp[ggg()]++;
    }

    fori(M)
        forj(M)
            if (dp[i][j] < 101)
                FOR(k, dp[i][j], 101)
                    gt[i][k] += mp[j];
    forj(q)
    {
        int k;
        scanf("%s%d", s, &k);
        int x = ggg();
        printf("%d\n", gt[x][k]);
    }
}

//{{{
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];
int gt[4096][101];

void run()
{
    ints(n, m, q);
    string s;
    int k;
    int M = 1 << n;
    vector<int> w(n);
    readln(w);

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

    fori(M)
        forj(M)
            FOR(k, 0, n)
                dp[i][j] += ((i & (1 << k)) == (j & (1 << k))) * w[n - 1 - k];
    forj(m)
    {
        readln(s);
        mp[ggg(s)]++;
    }

    fori(M)
        forj(M)
            if (dp[i][j] < 101)
                FOR(k, dp[i][j], 101)
                    gt[i][k] += mp[j];
    forj(q)
    {
        readln(s, k);
        writeln(gt[ggg(s)][k]);
    }
}

//{{{
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];
int gt[4096][101];

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

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

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

    fori(m)
        scanf("%s", s),
        mp[ggg(s)]++;

    fori(M)
        forj(M)
            FOR(k, dp[i][j], 101)
                gt[i][k] += mp[j];

    forj(q)
        scanf("%s%d", s, &k),
        printf("%d\n", gt[ggg(s)][k]);
}

//{{{
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];
    vector<int> degs;
    fori(n + 1) degs.pb(1 << i);

    auto ggg = [&]() {
        int ans = 0;
        ROF(i, n - 1, 0)
            if (s[i] == '1')
                ans += degs[n - i - 1];
        return ans;
    };

    fori(M)
        FOR(j, i, M)
        {
            int sm = 0;
            FOR(k, 0, n)
                sm += ((i & degs[k]) == (j & degs[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];
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]);

    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];
    auto ggg = [&]() {
        int ans = 0;
        fori(n)
            if (s[n - 1 - i] == '1')
                ans += 1 << i;
        return ans;
    };

    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];

void run()
{
    ints(n, m, q);
    int M = 1 << n;
    vector<int> w(n);
    readln(w);
    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;
        }
    forj(m)
    {
        string s;
        readln(s);
        mp[ggg(s)]++;
    }
    forj(q)
    {
        string t;
        int k;
        readln(t, k);
        int x = ggg(t);
        int ans = 0;
        fori(M)
            ans += mp[i] * (dp[x][i] <= k);
        writeln(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()
{
    char s[n];
    auto ggg = [&]() {
        int ans = 0;
        fori(n)
            if (s[n - 1 - i] == '1')
                ans += 1 << i;
        return ans;
    };

    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]);

    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(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;} //}}}


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], ans[4100][105], w[13];

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        int x = 0;
        for(int j = 0; j < n; j++) {
            char z; cin >> z; x = x * 2 + z - '0';
        }
        kol[x]++;
    }
    for (int i = 0; i <= 4096; ++i) {
        if (kol[i] == 0) continue;
        for (int j = 0; j <= 4096; ++j) {
            int c = 0, a1 = i, b1 = j;
            for (int l = 0; l < n; ++l) {
                if (a1 % 2 == b1 % 2)
                    c += w[n - l - 1];
                a1 >>= 1;
                b1 >>= 1;
                if(c > 100) break;
            }
            if(c > 100) continue;
            ans[j][100] += kol[i];
            if(c != 0)
                ans[j][c - 1] -= kol[i];
        }
    }
    for (int j = 0; j <= 4096; ++j) {
        for (int k = 99; k >= 0; --k) {
            ans[j][k] += ans[j][k + 1];
        }
    }
    for (int i = 0; i < q; ++i) {
        int x = 0;
        for(int j = 0; j < n; j++) {
            char z; cin >> z; x = x * 2 + z - '0';
        }
        int wi;
        cin >> wi;
        cout << ans[x][wi] << '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], ans[4100][105], w[13];

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        int x = 0;
        for(int j = 0; j < n; j++) {
            char z; cin >> z; x = x * 2 + z - '0';
        }
        kol[x]++;
    }
    for (int j = 0; j <= 4096; ++j) {
        for (int i = 0; i <= 4096; ++i) {
            int c = 0, a1 = i, b1 = j;
            for (int l = 0; l < n; ++l) {
                if (a1 % 2 == b1 % 2)
                    c += w[n - l - 1];
                a1 >>= 1;
                b1 >>= 1;
                if(c > 100) break;
            }
            if(c > 100) continue;
            ans[j][100] += kol[i];
            if(c != 0)
                ans[j][c - 1] -= kol[i];
        }
        for (int k = 99; k >= 0; --k) {
            ans[j][k] += ans[j][k + 1];
        }
    }
    for (int i = 0; i < q; ++i) {
        int x = 0;
        for(int j = 0; j < n; j++) {
            char z; cin >> z; x = x * 2 + z - '0';
        }
        int wi;
        cin >> wi;
        cout << ans[x][wi] << '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], qer[4100], ans[4100][105], w[13];

int ss[5 * nv];

int wix[5 * nv];

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 0; j >= 0; --j, ++h) {
            if(s[j] == '1'){
                x += ((h)<<1);
                if(h == 0) x++;
            }
        }
        kol[x]++;
    }
    for (int i = 0; i < q; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 0; j >= 0; --j, ++h) {
            if(s[j] == '1'){
                x += ((h)<<1);
                if(h == 0) x++;
            }
        }
        qer[x]++;
        int wi;
        cin >> wi;
        ans[x][wi] = 1;
        ss[i] = x;
        wix[i] = wi;
    }
    for (int i = 0; i <= 4096; ++i) {
        if(kol[i] == 0) continue;
        for (int j = 0; j <= 4096; ++j) {
            if(qer[j] == 0) continue;
            int c = 0, a1 = i, b1 = j;
            for (int l = 0; l < n; ++l) {
                if(a1%2 == b1%2)
                    c += w[n - l - 1];
                a1>>=1;
                b1>>=1;
            }
            for (int k = 0; k <= 100; ++k) {
                if(ans[j][k] == 0) continue;
                if(c <= k) ans[j][k] += kol[i];
            }
        }
    }
    for (int i = 0; i < q; ++i) {
        cout << ans[ss[i]][wix[i]] - 1<< '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], qer[4100], ans[4100][105], w[13];

int ss[5 * nv];

int wix[5 * nv];

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 0; j >= 0; --j, ++h) {
            if(s[j] == '1'){
                x += ((h)<<1);
                if(h == 0) x++;
            }
        }
        kol[x]++;
    }///
    for (int i = 0; i < q; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 0; j >= 0; --j, ++h) {
            if(s[j] == '1'){
                x += ((h)<<1);
                if(h == 0) x++;
            }
        }
        qer[x]++;
        int wi;
        cin >> wi;
        ans[x][wi] = 1;
        ss[i] = x;
        wix[i] = wi;
    }
    for (int i = 0; i <= 4096; ++i) {
        if(kol[i] == 0) continue;
        for (int j = 0; j <= 4096; ++j) {
            if(qer[j] == 0) continue;
            int c = 0, a1 = i, b1 = j;
            for (int l = 0; l < n; ++l) {
                if(a1%2 == b1%2)
                    c += w[n - l - 1];
                a1>>=1;
                b1>>=1;
            }
            for (int k = 0; k <= 100; ++k) {
                if(ans[j][k] == 0) continue;
                if(c <= k) ans[j][k] += kol[i];
            }
        }
    }
    for (int i = 0; i < q; ++i) {
        cout << ans[ss[i]][wix[i]] - 1<< '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], qer[4100], ans[4100][105], w[13];

    int ss[5 * nv];

    int wix[5 * nv];

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        int x = 0;
        for(int j = 0; j < n; j++) {
            char z; cin >> z; x = x * 2 + z - '0';
        }
        kol[x]++;
    }
    for (int i = 0; i < q; ++i) {
        int x = 0;
        for(int j = 0; j < n; j++) {
            char z; cin >> z; x = x * 2 + z - '0';
        }
        qer[x]++;
        int wi;
        cin >> wi;
        ss[i] = x;
        wix[i] = wi;
    }
    for (int i = 0; i <= 4096; ++i) {
        if (kol[i] == 0) continue;
        for (int j = 0; j <= 4096; ++j) {
            if (qer[j] == 0) continue;
            int c = 0, a1 = i, b1 = j;
            for (int l = 0; l < n; ++l) {
                if (a1 % 2 == b1 % 2)
                    c += w[n - l - 1];
                a1 >>= 1;
                b1 >>= 1;
            }
            if(c > 100) continue;
            ans[j][100] += kol[i];
            if(c != 0)
                ans[j][c - 1] -= kol[i];
        }
    }
    for (int j = 0; j <= 4096; ++j) {
        if (qer[j] == 0) continue;
        for (int k = 99; k >= 0; --k) {
            ans[j][k] += ans[j][k + 1];
        }
    }
    for (int i = 0; i < q; ++i) {
        cout << ans[ss[i]][wix[i]] << '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], qer[4100], ans[4100][105], w[13];

int ss[5 * nv];

int wix[5 * nv];

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 1; j >= 0; --j, h <<= 1) {
            if (s[j] == '1') {
                x += h;
            }
        }
        kol[x]++;
    }
    for (int i = 0; i < q; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 1; j >= 0; --j, h <<= 1) {
            if (s[j] == '1') {
                x += h;
            }
        }
        qer[x]++;
        int wi;
        cin >> wi;
        ss[i] = x;
        wix[i] = wi;
    }
    for (int i = 0; i <= 4096; ++i) {
        if (kol[i] == 0) continue;
        for (int j = 0; j <= 4096; ++j) {
            if (qer[j] == 0) continue;
            int c = 0, a1 = i, b1 = j;
            for (int l = 0; l < n; ++l) {
                if (a1 % 2 == b1 % 2)
                    c += w[n - l - 1];
                a1 >>= 1;
                b1 >>= 1;
            }
            ans[j][100] += kol[i];
            if(c != 0)
                ans[j][c - 1] -= kol[i];
        }
    }
    for (int j = 0; j <= 4096; ++j) {
        if (qer[j] == 0) continue;
        for (int k = 99; k >= 0; --k) {
            ans[j][k] += ans[j][k + 1];
        }
    }
    for (int i = 0; i < q; ++i) {
        cout << ans[ss[i]][wix[i]] << '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], qer[4100], ans[4100][105], w[13];

int ss[4100];

int wix[4100];

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 0; j >= 0; --j, ++h) {
            if(s[j] == '1'){
                x += ((h)<<1);
                if(h == 0) x++;
            }
        }
        kol[x]++;
    }
    for (int i = 0; i < q; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 0; j >= 0; --j, ++h) {
            if(s[j] == '1'){
                x += ((h)<<1);
                if(h == 0) x++;
            }
        }
        qer[x]++;
        int wi;
        cin >> wi;
        ans[x][wi] = 1;
        ss[i] = x;
        wix[i] = wi;
    }
    for (int i = 0; i <= 4096; ++i) {
        if(kol[i] == 0) continue;
        for (int j = 0; j <= 4096; ++j) {
            if(qer[j] == 0) continue;
            int c = 0, a1 = i, b1 = j;
            for (int l = 0; l < n; ++l) {
                if(a1%2 == b1%2)
                    c += w[n - l - 1];
                a1>>=1;
                b1>>=1;
            }
            for (int k = 0; k <= 100; ++k) {
                if(ans[j][k] == 0) continue;
                if(c <= k) ans[j][k] += kol[i];
            }
        }
    }
    for (int i = 0; i < q; ++i) {
        cout << ans[ss[i]][wix[i]] - 1<< '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], ans[4100][105], w[13], mask, n;

void gen(int x, int i, int sum) {
    if(sum > 100) return;
    if(i == n) ans[x][sum] += kol[mask];
    else {
        bool bit = (x & (1 << (n - i - 1))) != 0;
        mask *= 2;
        if(!bit) sum += w[i];
        gen(x, i + 1, sum);
        if(!bit) sum -= w[i];
        mask++;
        if(bit) sum += w[i];
        gen(x, i + 1, sum);
        if(bit) sum -= w[i];
        mask--;
        mask /= 2;
    }
}

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        int x = 0;
        for(int j = 0; j < n; j++) {
            char z; cin >> z; x = x * 2 + z - '0';
        }
        kol[x]++;
    }
    for (int j = 0; j <= 4096; ++j) {
        gen(j, 0, 0);
        for (int k = 1; k <= 100; ++k) {
            ans[j][k] += ans[j][k - 1];
        }
    }
    for (int i = 0; i < q; ++i) {
        int x = 0;
        for(int j = 0; j < n; j++) {
            char z; cin >> z; x = x * 2 + z - '0';
        }
        int wi;
        cin >> wi;
        cout << ans[x][wi] << '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], qer[4100], ans[4100][105], w[13];

int ss[5 * nv];

int wix[5 * nv];

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 0; j >= 0; --j, ++h) {
            if(s[j] == '1'){
                x += ((h)<<1);
            }
        }
        if(s[n - 1] == '1') x++;
        kol[x]++;
    }
    for (int i = 0; i < q; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 0; j >= 0; --j, ++h) {
            if(s[j] == '1'){
                x += ((h)<<1);
            }
        }
        if(s[n - 1] == '1') x++;
        qer[x]++;
        int wi;
        cin >> wi;
        ans[x][wi] = 1;
        ss[i] = x;
        wix[i] = wi;
    }
    for (int i = 0; i <= 4096; ++i) {
        if(kol[i] == 0) continue;
        for (int j = 0; j <= 4096; ++j) {
            if(qer[j] == 0) continue;
            int c = 0, a1 = i, b1 = j;
            for (int l = 0; l < n; ++l) {
                if(a1%2 == b1%2)
                    c += w[n - l - 1];
                a1>>=1;
                b1>>=1;
            }
            for (int k = 0; k <= 100; ++k) {
                if(ans[j][k] == 0) continue;
                if(c <= k) ans[j][k] += kol[i];
            }
        }
    }
    for (int i = 0; i < q; ++i) {
        cout << ans[ss[i]][wix[i]] - 1<< '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], qer[4100], ans[4100][105], w[13];

int ss[5 * nv];

int wix[5 * nv];

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 0; j >= 0; --j, ++h) {
            if(s[j] == '1'){
                x += ((h + 1)<<1)/2;
            }
        }
        kol[x]++;
    }
    for (int i = 0; i < q; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 0; j >= 0; --j, ++h) {
            if(s[j] == '1'){
                x += ((h + 1)<<1)/2;
            }
        }
        qer[x]++;
        int wi;
        cin >> wi;
        ans[x][wi] = 1;
        ss[i] = x;
        wix[i] = wi;
    }
    for (int i = 0; i <= 4096; ++i) {
        if(kol[i] == 0) continue;
        for (int j = 0; j <= 4096; ++j) {
            if(qer[j] == 0) continue;
            int c = 0, a1 = i, b1 = j;
            for (int l = 0; l < n; ++l) {
                if(a1%2 == b1%2)
                    c += w[n - l - 1];
                a1>>=1;
                b1>>=1;
            }
            for (int k = 0; k <= 100; ++k) {
                if(ans[j][k] == 0) continue;
                if(c <= k) ans[j][k] += kol[i];
            }
        }
    }
    for (int i = 0; i < q; ++i) {
        cout << ans[ss[i]][wix[i]] - 1<< '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], qer[4100], ans[4100][105], w[13];

int ss[5 * nv];

int wix[5 * nv];

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 1; j >= 0; --j, h <<= 1) {
            if (s[j] == '1') {
                x += h;
            }
        }
        kol[x]++;
    }
    for (int i = 0; i < q; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 1; j >= 0; --j, h <<= 1) {
            if (s[j] == '1') {
                x += h;
            }
        }
        qer[x]++;
        int wi;
        cin >> wi;
        ss[i] = x;
        wix[i] = wi;
    }
    for (int i = 0; i <= 4096; ++i) {
        if (kol[i] == 0) continue;
        for (int j = 0; j <= 4096; ++j) {
            if (qer[j] == 0) continue;
            int c = 0, a1 = i, b1 = j;
            for (int l = 0; l < n; ++l) {
                if (a1 % 2 == b1 % 2)
                    c += w[n - l - 1];
                a1 >>= 1;
                b1 >>= 1;
            }
            if(c > 100) continue;
            ans[j][100] += kol[i];
            if(c != 0)
                ans[j][c - 1] -= kol[i];
        }
    }
    for (int j = 0; j <= 4096; ++j) {
        if (qer[j] == 0) continue;
        for (int k = 99; k >= 0; --k) {
            ans[j][k] += ans[j][k + 1];
        }
    }
    for (int i = 0; i < q; ++i) {
        cout << ans[ss[i]][wix[i]] << '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("rmq.in","r",stdin);
#define output freopen("rmq.out","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
*/

int kol[4100], qer[4100], ans[4100][105], w[13];

int ss[5 * nv];

int wix[5 * nv];

int inline solve() {
    //input;//output;
    //fix;
    fast_io;
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 1; j >= 0; --j, h<<=1) {
            if(s[j] == '1'){
                x += h;
            }
        }
        kol[x]++;
    }
    for (int i = 0; i < q; ++i) {
        string s;
        cin >> s;
        int x = 0;
        for (int j = n - 1, h = 1; j >= 0; --j, h<<=1) {
            if(s[j] == '1'){
                x += h;
            }
        }
        qer[x]++;
        int wi;
        cin >> wi;
        ans[x][wi] = 1;
        ss[i] = x;
        wix[i] = wi;
    }
    for (int i = 0; i <= 4096; ++i) {
        if(kol[i] == 0) continue;
        for (int j = 0; j <= 4096; ++j) {
            if(qer[j] == 0) continue;
            int c = 0, a1 = i, b1 = j;
            for (int l = 0; l < n; ++l) {
                if(a1%2 == b1%2)
                    c += w[n - l - 1];
                a1>>=1;
                b1>>=1;
            }
            for (int k = 0; k <= 100; ++k) {
                if(ans[j][k] == 0) continue;
                if(c <= k) ans[j][k] += kol[i];
            }
        }
    }
    for (int i = 0; i < q; ++i) {
        cout << ans[ss[i]][wix[i]] - 1<< '\n';
    }
}
int32_t main() {
    //freopen("mushrooms.in", "r", stdin);
    //freopen("mushrooms.out", "w", stdout);
    solve();
}
/*
10 3 4
codeforces
for
1 3
3 10
5 6
4 6
 * */


#include <bits/stdc++.h>

#define int         long long
#define ld          long double
#define fastio      ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define sz(x)       (int)x.size()
#define mod         1000000007
#define mod2        998244353

using namespace std;

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
int gcd(int a,int b)
{
    if(a%b == 0)return b;
    return gcd(b,a%b);
}*/
int n,m,q,que[1<<12+5][105];
vector<int>mp(1<<12+5),w(15);
bool mpp[1<<12+5];
vector<pii >aa(500005);

signed main()
{
    fastio;
    cin >> n >> m >> q;
    FOR(i,0,n)
    cin >> w[i];
    FOR(i,0,m)
    {
        string s;
        cin >> s;
        int ans=0;
        FOR(j,0,n)
        ans += (s[j]-'0')*(1<<j);
        mp[ans]++;
    }
    FOR(i,0,(1<<n)+3)
    {
        if(!que[i])continue;
        char t[15];
        int x = i;
        FOR(j,0,n)
        {
        int d = x%2;
        x=x/2;
        t[j] = (char)(d+48);
        }
        FOR(j,0,(1<<n)+3)
        {
            if(!mp[j])continue;
            char s[15];
            int x = j;
            FOR(p,0,n)
            {
            int d = x%2;
            x=x/2;
            s[p] = (char)(d+48);
            }
            int val=0;
            FOR(p,0,n)
            if(t[p] == s[p])
            {val+=w[p];if(val>100)break;}
            if(val <= 100)que[i][val] += mp[j];
        }
    }
    FOR(i,0,(1<<n)+3)
    FOR(j,0,101)
    que[i][j] += que[i][j-1];

    FOR(i,1,q+1)
    {
        int ans=0,k;
        string t;
        cin >> t >> k;
        FOR(j,0,n)
        ans += (t[j]-'0')*(1<<j);
        cout << que[ans][k] << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define int         long long
#define ld          long double
#define fastio      ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define sz(x)       (int)x.size()
#define mod         1000000007
#define mod2        998244353

using namespace std;

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
int gcd(int a,int b)
{
    if(a%b == 0)return b;
    return gcd(b,a%b);
}*/
int n,m,q,que[1<<12+5][105];
vector<int>mp(1<<12+5),w(15);
bool mpp[1<<12+5];
vector<pii >aa(500005);

signed main()
{
    fastio;
    cin >> n >> m >> q;
    FOR(i,0,n)
    cin >> w[i];
    FOR(i,0,m)
    {
        string s;
        cin >> s;
        int ans=0;
        FOR(j,0,n)
        ans += (s[j]-'0')*(1<<j);
        mp[ans]++;
    }
    FOR(i,0,(1<<n)+3)
    {
        if(!que[i])continue;
        string t;
        int x = i;
        FOR(j,0,n)
        {
        int d = x%2;
        x=x/2;
        t[j] = (char)(d+48);
        }
        FOR(j,0,(1<<n)+3)
        {
            if(!mp[j])continue;
            string s;
            int x = j;
            FOR(p,0,n)
            {
            int d = x%2;
            x=x/2;
            s[p] = (char)(d+48);
            }
            int val=0;
            FOR(p,0,n)
            if(t[p] == s[p])if(val+w[p]<=100)val+=w[p];else break;
            que[i][val] += mp[j];
        }
    }
    FOR(i,0,(1<<n)+3)
    FOR(j,1,101)
    que[i][j] += que[i][j-1];

    FOR(i,1,q+1)
    {
        int ans=0,k;
        string t;
        cin >> t >> k;
        FOR(j,0,n)
        ans += (t[j]-'0')*(1<<j);
        cout << que[ans][k] << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define int         long long
#define ld          long double
#define fastio      ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define sz(x)       (int)x.size()
#define mod         1000000007
#define mod2        998244353

using namespace std;

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
int gcd(int a,int b)
{
    if(a%b == 0)return b;
    return gcd(b,a%b);
}*/
int n,m,q,que[1<<12+5][105];
vector<int>mp(1<<12+5),w(15);
bool mpp[1<<12+5];
vector<pii >aa(500005);

signed main()
{
    fastio;
    cin >> n >> m >> q;
    FOR(i,0,n)
    cin >> w[i];
    FOR(i,0,m)
    {
        string s;
        cin >> s;
        int ans=0;
        FOR(j,0,n)
        ans += (s[j]-'0')*(1<<j);
        mp[ans]++;
    }
    FOR(i,0,(1<<n)+3)
    {
        if(!que[i])continue;
        char t[15];
        int x = i;
        FOR(j,0,n)
        {
        int d = x%2;
        x=x/2;
        t[j] = (char)(d+48);
        }
        FOR(j,0,(1<<n)+3)
        {
            if(!mp[j])continue;
            char s[15];
            int x = j;
            FOR(p,0,n)
            {
            int d = x%2;
            x=x/2;
            s[p] = (char)(d+48);
            }
            int val=0;
            FOR(p,0,n)
            if(t[p] == s[p])
            {if(val+w[p]<=100)val+=w[p];else break;}
            que[i][val] += mp[j];
        }
    }
    FOR(i,0,(1<<n)+3)
    FOR(j,0,101)
    que[i][j] += que[i][j-1];

    FOR(i,1,q+1)
    {
        int ans=0,k;
        string t;
        cin >> t >> k;
        FOR(j,0,n)
        ans += (t[j]-'0')*(1<<j);
        cout << que[ans][k] << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define int         long long
#define ld          long double
#define fastio      ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define sz(x)       (int)x.size()
#define mod         1000000007
#define mod2        998244353

using namespace std;

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
int gcd(int a,int b)
{
    if(a%b == 0)return b;
    return gcd(b,a%b);
}*/
int n,m,q,que[1<<12+5][105];
vector<int>mp(1<<12+5),w(15);
bool mpp[1<<12+5];
vector<pii >aa(500005);

signed main()
{
    fastio;
    cin >> n >> m >> q;
    FOR(i,0,n)
    cin >> w[i];
    FOR(i,0,m)
    {
        string s;
        cin >> s;
        int ans=0;
        FOR(j,0,n)
        ans += (s[j]-'0')*(1<<j);
        mp[ans]++;
    }
    FOR(i,0,(1<<n)+3)
    {
        if(!que[i])continue;
        char t[15];
        int x = i;
        FOR(j,0,n)
        {
        int d = x%2;
        x=x/2;
        t[j] = (char)(d+48);
        }
        FOR(j,0,(1<<n)+3)
        {
            if(!mp[j])continue;
            char s[15];
            int x = j;
            FOR(p,0,n)
            {
            int d = x%2;
            x=x/2;
            s[p] = (char)(d+48);
            }
            int val=0;
            FOR(p,0,n)
            if(t[p] == s[p])
            {if(val+w[p]<=100)val+=w[p];else break;}
            que[i][val] += mp[j];
        }
    }
    FOR(i,0,(1<<n)+3)
    FOR(j,1,101)
    que[i][j] += que[i][j-1];

    FOR(i,1,q+1)
    {
        int ans=0,k;
        string t;
        cin >> t >> k;
        FOR(j,0,n)
        ans += (t[j]-'0')*(1<<j);
        cout << que[ans][k] << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define int         long long
#define ld          long double
#define fastio      ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define sz(x)       (int)x.size()
#define mod         1000000007
#define mod2        998244353

using namespace std;

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
int gcd(int a,int b)
{
    if(a%b == 0)return b;
    return gcd(b,a%b);
}*/
int n,m,q,que[1<<12+5][105];
vector<int>mp(1<<12+5),w(15);
bool mpp[1<<12+5];
vector<pii >aa(500005);

signed main()
{
    fastio;
    cin >> n >> m >> q;
    FOR(i,0,n)
    cin >> w[i];
    FOR(i,0,m)
    {
        string s;
        cin >> s;
        int ans=0;
        FOR(i,0,n)
        ans += (s[i]-'0')*(1<<i);
        mp[ans]++;
    }
    FOR(i,1,q+1)
    {
        int ans=0,k;
        string t;
        cin >> t >> k;
        FOR(j,0,n)
        ans += (t[j]-'0')*(1<<j);
        mpp[ans]=1;
        aa[i]={ans,k};
    }
    FOR(i,0,(1<<n)+3)
    {
        if(!mpp[i])continue;
        string t;
        int x = i;
        FOR(j,0,n)
        {
        int d = x%2;
        x=x/2;
        t[j] = (char)(d+48);
        }
        FOR(j,0,(1<<n)+3)
        {
            if(!mp[j])continue;
            string s;
            int x = j;
            FOR(p,0,n)
            {
            int d = x%2;
            x=x/2;
            s[p] = (char)(d+48);
            }
            int val=0;
            FOR(p,0,n)
            if(t[p] == s[p])if(val+w[p]<=100)val+=w[p];else break;
            que[i][val] += mp[j];
        }
    }
    FOR(i,0,(1<<n)+3)
    FOR(j,1,101)
    que[i][j] += que[i][j-1];

    FOR(i,1,q+1)
    {
        cout << que[aa[i].f][aa[i].se] << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

int lcm(int x, int y) {
	return x * y / __gcd(x, y);
}

void solve() {

	int a, b; cin >> a >> b;

	string s;
	cin >> s;

	int st = 0, et = 0, noz = 0, res = 0;
	for (int i = 1; i < s.size() - 1; i++) {
		if (s[i - 1] == '1' && s[i] == '0')st = i - 1;

		if (s[i] == '0' && s[i + 1] == '1') {
			et = i + 1;
			noz = et - st - 1;

			res = res + (noz * b + a);

		}
	}

	int f = 0, ans = 0, cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') {
			cnt++;
			f = 1;
			continue;
		}
		else {
			if (f == 1) {
				ans += a;
				f = 0;
			}

			cnt = 0;

		}
	}
	if (f == 1)ans += a;

	if (res == 0)cout << ans << endl;
	else if (ans == 0)cout << res << endl;
	else
		cout << min(ans, res) << endl;

}

int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t = 1;
	int t; cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

int lcm(int x, int y) {
	return x * y / __gcd(x, y);
}

void solve() {

	int a, b; cin >> a >> b;

	string s;
	cin >> s;

	int st = 0, et = 0, noz = 0, res = 0;
	for (int i = 1; i < s.size() - 1; i++) {
		if (s[i - 1] == '1' && s[i] == '0')st = i - 1;

		if (s[i] == '0' && s[i + 1] == '1') {
			et = i + 1;
			noz = et - st - 1;

			res = res + (noz * b + a);

		}
	}

	int f = 0, ans = 0, cnt = 0;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == '1') {
			cnt++;
			f = 1;
			continue;
		}
		else {
			if (f == 1) {
				ans += a;
				f = 0;
			}

			cnt = 0;

		}
	}
	if (f == 1)ans += a;

	if (res == 0)cout << ans << endl;
	else if (ans == 0)cout << res << endl;
	else
		cout << min(ans, res) << endl;

}

int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t = 1;
	int t; cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

int lcm(int x, int y) {
	return x * y / __gcd(x, y);
}

void solve() {

	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;

	bool flag = true;
	vector<int>v;
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1')
			v.pb(i);

	}
	// for (auto x : v)cout << x << endl;
	int ans = 0, res = 0;
	for (int i = 1; i < v.size(); i++) {
		int noz = (v[i ] - v[i - 1]) - 1;
		if (noz > 0) {
			ans += (a + noz * b);
			res += a;
			flag = false;
		}

	}
	res += a;
	int l = v.size();

	if (l == s.size()) {
		cout << a << endl;
		return;
	}
	if (v.size() == 1) {
		cout << a << endl;
		return;
	}

	else if (flag == true) {
		cout << res << endl;
		return;
	}

	cout << min(res, ans) << endl;

}

int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t = 1;
	int t; cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

int lcm(int x, int y) {
	return x * y / __gcd(x, y);
}

void solve() {

	int a, b; cin >> a >> b;

	string s;
	cin >> s;

	int st = 0, et = 0, noz = 0, res = 0;
	bool flag = 0, g = 0;
	for (int i = 1; i < s.size() - 1; i++) {
		if (s[i - 1] == '1' && s[i] == '0') {
			st = i - 1;
			flag = 1;
		}

		if (s[i] == '0' && s[i + 1] == '1' && flag == 1) {
			et = i + 1;
			noz = et - st - 1;
			res += noz;
			// res = res + (noz * b + a);

			flag = 0;
		}
		g = 1;
	}

	if (g == 1)
		res = res * b + a;

	int f = 0, ans = 0, cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1' ) {
			cnt++;
			f = 1;
			continue;
		}
		else {
			if (f == 1) {
				ans += a;
				f = 0;
			}

			cnt = 0;

		}
	}
	if (f == 1)ans += a;

	if (res == 0)cout << ans << endl;
	else if (ans == 0)cout << res << endl;
	else
		cout << min(ans, res) << endl;

}

int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t = 1;
	int t; cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

int lcm(int x, int y) {
	return x * y / __gcd(x, y);
}

void solve() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	int n = s.size();
	int k = 0, ans = 0;
	int prev = INT_MIN;

	for (int i = 0; i < n; i++) {
		if (s[i] == '0')continue;

		int l = i - prev;
		l--;

		if (a >= b * l)
			ans += b * l;
		else
			ans += a;

		prev = i;

	}

	cout << ans << endl;

}

int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t = 1;
	int t; cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

int lcm(int x, int y) {
	return x * y / __gcd(x, y);
}

void solve() {

	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;

	bool flag = true;
	vector<int>v;
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1')
			v.pb(i);

	}
	// for (auto x : v)cout << x << endl;
	if (v.size() == 0) {
		cout << 0 << endl;
		return;
	}
	int ans = 0, res = 0;
	for (int i = 1; i < v.size(); i++) {
		int noz = (v[i ] - v[i - 1]) - 1;
		if (noz > 0) {
			ans += (a + noz * b);
			res += a;
			flag = false;
		}

	}
	res += a;
	int l = v.size();

	if (l == s.size()) {
		cout << a << endl;
		return;
	}
	if (v.size() == 1) {
		cout << a << endl;
		return;
	}

	else if (flag == true) {
		cout << res << endl;
		return;
	}

	cout << min(res, ans) << endl;

}

int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t = 1;
	int t; cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

int lcm(int x, int y) {
	return x * y / __gcd(x, y);
}

void solve() {

	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;

	bool flag = true;
	vector<int>v;
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1')
			v.pb(i);

	}
	// for (auto x : v)cout << x << endl;
	int ans = 0, res = 0;
	for (int i = 1; i < v.size(); i++) {
		int noz = (v[i ] - v[i - 1]) - 1;
		if (noz > 0) {
			ans += (a + noz * b);
			res += a;
		}

	}
	res += a;
	int l = v.size();

	if (l == s.size()) {
		cout << a << endl;
		return;
	}
	if (v.size() == 1) {
		cout << a << endl;
		return;
	}

	cout << min(res, ans) << endl;

}

int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t = 1;
	int t; cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

int lcm(int x, int y) {
	return x * y / __gcd(x, y);
}

void solve() {

	int a, b; cin >> a >> b;

	string s;
	cin >> s;

	int st = 0, et = 0, noz = 0, res = 0;
	bool flag = 0;
	for (int i = 1; i < s.size() - 1; i++) {
		if (s[i - 1] == '1' && s[i] == '0') {
			st = i - 1;
			flag = 1;
		}

		if (s[i] == '0' && s[i + 1] == '1' && flag == 1) {
			et = i + 1;
			noz = et - st - 1;
			res += noz;
			// res = res + (noz * b + a);

			flag = 0;
		}
	}

	res = res * b + a;

	int f = 0, ans = 0, cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1' ) {
			cnt++;
			f = 1;
			continue;
		}
		else {
			if (f == 1) {
				ans += a;
				f = 0;
			}

			cnt = 0;

		}
	}
	if (f == 1)ans += a;

	if (res == 0)cout << ans << endl;
	else if (ans == 0)cout << res << endl;
	else
		cout << min(ans, res) << endl;

}

int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t = 1;
	int t; cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

int lcm(int x, int y) {
	return x * y / __gcd(x, y);
}

void solve() {

	int a, b; cin >> a >> b;

	string s;
	cin >> s;

	int st = 0, et = 0, noz = 0, res = 0;
	for (int i = 1; i < s.size() - 1; i++) {
		if (s[i - 1] == '1' && s[i] == '0')st = i - 1;

		if (s[i] == '0' && s[i + 1] == '1') {
			et = i + 1;
			noz = et - st - 1;

			res = res + (noz * b + a);

		}
	}

	int f = 0, ans = 0, cnt = 0;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == '1') {
			cnt++;
			f = 1;
			continue;
		}
		else {
			if (f == 1) {
				ans += a;
				f = 0;
			}

			cnt = 0;

		}
	}

	if (res == 0)cout << ans << endl;
	else if (ans == 0)cout << res << endl;
	else
		cout << min(ans, res) << endl;

}

int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t = 1;
	int t; cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}


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

void solve()
{
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	int n=s.size();
	int count0=0;
	int cost=0;
	int start=0,endd=n;
	for(int i=0;i<n;i++){
        if(s[i]=='0'){
            start++;
        }
        else
            break;
	}
	for(int i=n-1;i>0;i--){
        if(s[i]=='0'){
            endd--;
        }
        else
            break;
	}
	if(a>=b){
        for(int i=start;i<endd;i++){
            if(s[i]=='1' && s[i+1]=='1')
                continue;
            else if(s[i]=='1' && s[i+1]!='1')
                cost=cost+a;
            else if(s[i]=='0' && s[i+1]=='0')
                count0++;
            else if(s[i]=='0' && s[i+1]!='0'){
                count0++;
                if(count0<=a){
                    cost=cost-(a-(count0*b));
                }
                count0=0;
            }
        }
        cout<<cost;
	}
	else{
        for(int i=start;i<endd;i++){
            if(s[i]=='1' && s[i+1]=='1')
                continue;
            if(s[i]=='1' && s[i+1]!='1')
                cost=cost+a;
            if(s[i]=='0' && s[i+1]=='0')
                continue;
        }
        cout<<cost;
	}
	cout<<"\n";
}

int main()
{
	int t;
	cin>>t;
	while(t--){
        solve();
	}
	return 0;
}


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

void solve()
{
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	int n=s.size();
	int count0=0;
	int cost=0;
	int start=0,endd=n;
	for(int i=0;i<n;i++){
        if(s[i]=='0'){
            start++;
        }
        else
            break;
	}
	for(int i=n-1;i>0;i--){
        if(s[i]=='0'){
            endd--;
        }
        else
            break;
	}
	if(a>=b){
        for(int i=start;i<endd;i++){
            if(s[i]=='1' && s[i+1]=='1');//skip
            else if(s[i]=='1' && s[i+1]!='1'){
                cost=cost+a;
            }
            else if(s[i]=='0' && s[i+1]=='0'){
                count0++;
            }
            else if(s[i]=='0' && s[i+1]!='0'){
                count0++;
                if(count0<=a){
                    cost=cost-(a-(count0*b));
                }
                count0=0;
            }
        }
        cout<<cost;
	}
	else{
        for(int i=start;i<n;i++){
            if(s[i]==1 && s[i+1]==1);//skip
            if(s[i]==1 && s[i+1]!=1){
                cost=cost+a;
            }
            if(s[i]==0 && s[i+1]==0);//skip
        }
        cout<<cost;
	}
	cout<<"\n";
}

int main()
{
	int t;
	cin>>t;
	while(t--){
        solve();
	}
	return 0;
}


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

void solve()
{
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	int n=s.size();
	int count0=0;
	int cost=0;
	int start=0,endd=n;
	for(int i=0;i<n;i++){
        if(s[i]=='0'){
            start++;
        }
        else
            break;
	}
	for(int i=n-1;i>0;i--){
        if(s[i]=='0'){
            endd--;
        }
        else
            break;
	}
	if(a>=b){
        for(int i=start;i<endd;i++){
            if(s[i]=='1' && s[i+1]=='1');//skip
            else if(s[i]=='1' && s[i+1]!='1'){
                cost=cost+a;
            }
            else if(s[i]=='0' && s[i+1]=='0'){
                count0++;
            }
            else if(s[i]=='0' && s[i+1]!='0'){
                count0++;
                if(count0<=a){
                    cost=cost-(a-(count0*b));
                }
                count0=0;
            }
        }
        cout<<cost;
	}
	else{
        for(int i=start;i<n;i++){
            if(s[i]==1 && s[i+1]==1);skip
            if(s[i]==1 && s[i+1]!=1){
                cost=cost+a;
            }
            if(s[i]==0 && s[i+1]==0);//skip
        }
        cout<<cost;
	}
	cout<<"\n";
}

int main()
{
	int t;
	cin>>t;
	while(t--){
        solve();
	}
	return 0;
}


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

void solve()
{
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	s=s+'0';
	int n=s.size();
	int count0=0;
	int cost=0;
	int start=0,endd=n;
	for(int i=0;i<n;i++){
        if(s[i]=='0'){
            start++;
        }
        else
            break;
	}
	for(int i=n-1;i>0;i--){
        if(s[i]=='0'){
            endd--;
        }
        else
            break;
	}
	if(a>=b){
        for(int i=start;i<endd;i++){
            if(s[i]=='1' && s[i+1]=='1')
                continue;
            else if(s[i]=='1' && s[i+1]!='1')
                cost=cost+a;
            else if(s[i]=='0' && s[i+1]=='0')
                count0++;
            else if(s[i]=='0' && s[i+1]!='0'){
                count0++;
                if(count0<=a){
                    cost=cost-(a-(count0*b));
                }
                count0=0;
            }
        }
        cout<<cost;
	}
	else{
        for(int i=start;i<endd;i++){
            if(s[i]=='1' && s[i+1]=='1')
                continue;
            if(s[i]=='1' && s[i+1]!='1')
                cost=cost+a;
            if(s[i]=='0' && s[i+1]=='0')
                continue;
        }
        cout<<cost;
	}
	cout<<"\n";
}

int main()
{
	int t;
	cin>>t;
	while(t--){
        solve();
	}
	return 0;
}


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

void solve()
{
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	s=s+'0';
	int n=s.size();
	int count0=0;
	int cost=0;
	int start=0,endd=n;
	for(int i=0;i<n;i++){
        if(s[i]=='0')
            start++;
        else
            break;
	}
	for(int i=n-1;i>0;i--){
        if(s[i]=='0')
            endd--;
        else
            break;
	}
    for(int i=start;i<endd;i++){
        if(s[i]=='1' && s[i+1]=='1')
            continue;
        else if(s[i]=='1' && s[i+1]!='1')
            cost=cost+a;
        else if(s[i]=='0' && s[i+1]=='0')
            count0++;
        else if(s[i]=='0' && s[i+1]!='0'){
            count0++;
            if((count0*b)<=a)
                cost=cost-(a-(count0*b));
            count0=0;
        }
    }
    cout<<cost<<"\n";
}

int main()
{
	int t;
	cin>>t;
	while(t--){
        solve();
	}
	return 0;
}


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

void solve()
{
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	//s=s+'0';
	int n=s.size();
	int count0=0;
	int cost=0;
	int start=0,endd=n;
	for(int i=0;i<n;i++){
        if(s[i]=='0')
            start++;
        else
            break;
	}
	for(int i=n-1;i>0;i--){
        if(s[i]=='0')
            endd--;
        else
            break;
	}
    for(int i=start;i<endd;i++){
        if(s[i]=='1' && s[i+1]=='1')
            continue;
        else if(s[i]=='1' && s[i+1]!='1')
            cost=cost+a;
        else if(s[i]=='0' && s[i+1]=='0')
            count0++;
        else if(s[i]=='0' && s[i+1]!='0'){
            count0++;
            if((count0*b)<=a)
                cost=cost-(a-(count0*b));
            count0=0;
        }
    }
    cout<<cost<<"\n";
}

int main()
{
	int t;
	cin>>t;
	while(t--){
        solve();
	}
	return 0;
}


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

void solve()
{
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	int n=s.size();
	int count0=0;
	int cost=0;
	int start=0,endd=n;
	for(int i=0;i<n;i++){
        if(s[i]=='0'){
            start++;
        }
        else
            break;
	}
	for(int i=n-1;i>0;i--){
        if(s[i]=='0'){
            endd--;
        }
        else
            break;
	}
	if(a>=b){
        for(int i=start;i<endd;i++){
            if(s[i]=='1' && s[i+1]=='1')
                continue;
            else if(s[i]=='1' && s[i+1]!='1')
                cost=cost+a;
            else if(s[i]=='0' && s[i+1]=='0')
                count0++;
            else if(s[i]=='0' && s[i+1]!='0'){
                count0++;
                if(count0<=a){
                    cost=cost-(a-(count0*b));
                }
                count0=0;
            }
        }
        cout<<cost;
	}
	else{
        for(int i=start;i<n;i++){
            if(s[i]=='1' && s[i+1]=='1')
                continue;
            if(s[i]=='1' && s[i+1]!='1')
                cost=cost+a;
            if(s[i]=='0' && s[i+1]=='0')
            continue;
        }
        cout<<cost;
	}
	cout<<"\n";
}

int main()
{
	int t;
	cin>>t;
	while(t--){
        solve();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define dbg(x,y) cout<<x<<" "<<y<<"\n"
#define rep(i,a,b) for(int i=a;i<b;i++)
#define drep(i,a,b) for(int i=a;i>b;i--)
#define pb push_back
#define sz(x) ((int)x.size())
#define F first
#define S second
#define vt vector<int>
#define INF 1e18
#define all(a) a.begin(),a.end()
#define pa pair<int,int>
int M=998244353,fact[500001];

void read(vt &a)
{
    rep(i,0,sz(a))
    {
        cin>>a[i];
    }
}

void print(vt &a)
{
    for(auto i:a)
    {
        cout<<i<<" ";
    }
    cout<<"\n";
}

void solve()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    int n=sz(s);
    bool flag=0;
    int count=0;
    int ans=0;
    rep(i,0,n)
    {
        if(flag==0)
        {
            if(s[i]=='0')
            {
                continue;
            }
            else
            {
                flag=1;
                ans+=a;
            }
        }
        else
        {
            if(s[i]=='0')
            {
                count++;
            }
            else
            {
                ans+=min(count*b,a);
                count=0;
            }
        }
    }
    cout<<ans<<"\n";
}

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}