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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
char c[4];
bool pitaj(long long x,long long y)
{
    printf("%lld %lld\n",x,y);
    fflush(stdout);
    //cout.flush();
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        if(x==y)
        {
            exit(0);
        }
        return true;
    }
    return false;
}
int main()
{
    srand(time(NULL));
    long long n;
    long long k;
    scanf("%lld %lld",&n,&k);
    long long a=1,b=n;
    while(true)
    {
        long long razlika=b-a+1;
        if(razlika>4*k+3)
        {
            long long mid=(a+b)/2;
            if(pitaj(a,mid))
            {
                b=mid-1;
            }
            else
            {
                a=mid+1;
            }
        }
        else
        {
            long long rnd=a+rand()%razlika;
            pitaj(rnd,rnd);
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
char c[4];
bool pitaj(long long x,long long y)
{
    printf("%lld %lld\n",x,y);
    fflush(stdout);
    //cout.flush();
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        if(x==y)
        {
            exit(0);
        }
        return true;
    }
    return false;
}
int main()
{
    //srand(time(NULL));
    long long n;
    long long k;
    scanf("%lld %lld",&n,&k);
    long long a=1,b=n;
    while(true)
    {
        long long razlika=b-a+1;
        if(razlika>4*k+3)
        {
            long long mid=(a+b)/2;
            if(pitaj(a,mid))
            {
                b=mid;
            }
            else
            {
                a=mid+1;
            }
        }
        else
        {
            long long rnd=a+rand()%razlika;
            pitaj(rnd,rnd);
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
bool pitaj(long long x,long long y)
{
    printf("%I64d %I64d\n",x,y);
    fflush(stdout);
    //cout.flush();
    char c[4];
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        return true;
    }
    return false;
}
int main()
{
    srand (time(NULL));
    long long n;
    int k;
    scanf("%I64d %i",&n,&k);
    long long a=1,b=n;
    while(true)
    {
        while(b-a>4*k+4)
        {
            long long mid=(a+b)/2;
            //printf("Pitam %lld %lld\n",a,mid);
            if(pitaj(a,mid))
            {
                b=mid-1;
            }
            else
            {
                a=mid+1;
            }
            a=max((long long)1,a-k);
            b=min(n,b+k);
            //printf("%lld %lld\n",a,b);
        }
        if(a==b)
        {
            pitaj(a,b);
            return 0;
        }
        int razlika=b-a;
        int rnd=rand()%razlika;
        //printf("%i\n",razlika);
        if(pitaj(a+rnd,a+rnd))
        {
            return 0;
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
bool pitaj(long long x,long long y)
{
    printf("%I64d %I64d\n",x,y);
    fflush(stdout);
    //cout.flush();
    char c[4];
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        return true;
    }
    return false;
}
int main()
{
    //srand (time(NULL));
    long long n;
    int k;
    scanf("%I64d %i",&n,&k);
    long long a=1,b=n;
    while(true)
    {
        //printf("AB: %lld %lld\n",a,b);
        while(b-a>4*k+4)
        {
            long long mid=(a+b)/2;
            //printf("Pitam %lld %lld\n",a,mid);
            if(pitaj(a,mid))
            {
                b=mid-1;
            }
            else
            {
                a=mid+1;
            }
            a=max((long long)1,a-k);
            b=min(n,b+k);
            //printf("AB: %lld %lld\n",a,b);
        }
        /*if(a==b)
        {
            pitaj(a,b);
            return 0;
        }*/
        int razlika=b-a;
        int rnd=rand()%(razlika+1);
        //printf("%i\n",razlika);
        if(pitaj(a+rnd,a+rnd))
        {
            return 0;
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
char c[4];
bool pitaj(long long x,long long y)
{
    printf("%lld %lld\n",x,y);
    fflush(stdout);
    //cout.flush();
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        if(x==y)
        {
            exit(0);
        }
        return true;
    }
    return false;
}
int main()
{
    //srand(time(NULL));
    long long n;
    long long k;
    scanf("%lld %lld",&n,&k);
    long long a=1,b=n;
    while(true)
    {
        long long razlika=b-a+1;
        if(razlika>4*k+3)
        {
            long long mid=(a+b)/2;
            if(pitaj(a,mid))
            {
                b=mid;
            }
            else
            {
                a=mid;
            }
        }
        else
        {
            long long rnd=a+rng()%razlika;
            pitaj(rnd,rnd);
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
bool pitaj(long long x,long long y)
{
    printf("%I64d %I64d\n",x,y);
    fflush(stdout);
    //cout.flush();
    char c[4];
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        return true;
    }
    return false;
}
int main()
{
    //srand (time(NULL));
    long long n;
    int k;
    scanf("%I64d %i",&n,&k);
    long long a=1,b=n;
    while(true)
    {
        while(b-a>4*k+4)
        {
            long long mid=(a+b)/2;
            //printf("Pitam %lld %lld\n",a,mid);
            if(pitaj(a,mid))
            {
                b=mid-1;
            }
            else
            {
                a=mid+1;
            }
            a=max((long long)1,a-k);
            b=min(n,b+k);
            //printf("%lld %lld\n",a,b);
        }
        if(a==b)
        {
            pitaj(a,b);
            return 0;
        }
        int razlika=b-a;
        int rnd=rand()%razlika;
        //printf("%i\n",razlika);
        if(pitaj(a+rnd,a+rnd))
        {
            return 0;
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
bool pitaj(long long x,long long y)
{
    printf("%I64d %I64d\n",x,y);
    fflush(stdout);
    //cout.flush();
    char c[4];
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        return true;
    }
    return false;
}
int main()
{
    srand(time(NULL));
    long long n;
    int k;
    scanf("%I64d %i",&n,&k);
    long long a=1,b=n;
    while(true)
    {
        //printf("AB: %lld %lld\n",a,b);
        while(b-a>4*k+1)
        {
            long long mid=(a+b)/2;
            //printf("Pitam %lld %lld\n",a,mid);
            if(pitaj(a,mid))
            {
                b=mid-1;
            }
            else
            {
                a=mid+1;
            }
            a=max((long long)1,a-k);
            b=min(n,b+k);
            //printf("AB: %lld %lld\n",a,b);
        }
        /*if(a==b)
        {
            pitaj(a,b);
            return 0;
        }*/
        int razlika=b-a;
        int rnd=rand()%(razlika+1);
        //printf("%i\n",razlika);
        if(pitaj(a+rnd,a+rnd))
        {
            return 0;
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
bool pitaj(long long x,long long y)
{
    printf("%I64d %I64d\n",x,y);
    char c[4];
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        return true;
    }
    return false;
}
int main()
{
    srand (time(NULL));
    long long n;
    int k;
    scanf("%I64d %i",&n,&k);
    long long a=0,b=n;
    while(true)
    {
        while(b-a>4*k+4)
        {
            long long mid=(a+b)/2;
            //printf("Pitam %lld %lld\n",a,mid);
            if(pitaj(a,mid))
            {
                b=mid-1;
            }
            else
            {
                a=mid+1;
            }
            a=max((long long)1,a-k);
            b=min(n,b+k);
            //printf("%lld %lld\n",a,b);
        }
        int razlika=b-a;
        int rnd=rand()%razlika;
        if(pitaj(a+rnd,a+rnd))
        {
            return 0;
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
bool pitaj(long long x,long long y)
{
    printf("%I64d %I64d\n",x,y);
    fflush(stdout);
    //cout.flush();
    char c[4];
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        return true;
    }
    return false;
}
int main()
{
    srand (time(NULL));
    long long n;
    int k;
    scanf("%I64d %i",&n,&k);
    long long a=1,b=n;
    while(true)
    {
        while(b-a>4*k+4)
        {
            long long mid=(a+b)/2;
            //printf("Pitam %lld %lld\n",a,mid);
            if(pitaj(a,mid))
            {
                b=mid-1;
            }
            else
            {
                a=mid+1;
            }
            a=max((long long)1,a-k);
            b=min(n,b+k);
            //printf("%lld %lld\n",a,b);
        }
        int razlika=b-a;
        int rnd=rand()%razlika;
        //printf("%i\n",razlika);
        if(pitaj(a+rnd,a+rnd))
        {
            return 0;
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
bool pitaj(long long x,long long y)
{
    printf("%I64d %I64d\n",x,y);
    fflush(stdout);
    //cout.flush();
    char c[4];
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        return true;
    }
    return false;
}
int main()
{
    srand(time(NULL));
    long long n;
    int k;
    scanf("%I64d %i",&n,&k);
    long long a=1,b=n;
    while(true)
    {
        //printf("AB: %lld %lld\n",a,b);
        while(b-a>4*k+4)
        {
            long long mid=(a+b)/2;
            //printf("Pitam %lld %lld\n",a,mid);
            if(pitaj(a,mid))
            {
                b=mid-1;
            }
            else
            {
                a=mid+1;
            }
            a=max((long long)1,a-k);
            b=min(n,b+k);
            //printf("AB: %lld %lld\n",a,b);
        }
        /*if(a==b)
        {
            pitaj(a,b);
            return 0;
        }*/
        int razlika=b-a;
        int rnd=rand()%(razlika+1);
        //printf("%i\n",razlika);
        if(pitaj(a+rnd,a+rnd))
        {
            return 0;
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
char c[4];
bool pitaj(long long x,long long y)
{
    printf("%lld %lld\n",x,y);
    fflush(stdout);
    //cout.flush();
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        if(x==y)
        {
            exit(0);
        }
        return true;
    }
    return false;
}
int main()
{
    //srand(time(NULL));
    long long n;
    long long k;
    scanf("%lld %lld",&n,&k);
    long long a=1,b=n;
    while(true)
    {
        long long razlika=b-a+1;
        if(razlika>4*k+3)
        {
            long long mid=(a+b)/2;
            if(pitaj(a,mid))
            {
                b=mid-1;
            }
            else
            {
                a=mid+1;
            }
        }
        else
        {
            long long rnd=a+rng()%razlika;
            pitaj(rnd,rnd);
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
char c[4];
bool pitaj(long long x,long long y)
{
    printf("%lld %lld\n",x,y);
    fflush(stdout);
    //cout.flush();
    scanf("%s",c);
    if(c[0]=='B')
    {
        exit(0);
    }
    if(c[0]=='Y')
    {
        if(x==y)
        {
            exit(0);
        }
        return true;
    }
    return false;
}
int main()
{
    srand(time(NULL));
    long long n;
    long long k;
    scanf("%lld %lld",&n,&k);
    long long a=1,b=n;
    while(true)
    {
        long long razlika=b-a+1;
        if(razlika>4*k+3)
        {
            long long mid=(a+b)/2;
            if(pitaj(a,mid))
            {
                b=mid;
            }
            else
            {
                a=mid;
            }
        }
        else
        {
            long long rnd=a+rand()%razlika;
            pitaj(rnd,rnd);
        }
        a=max((long long)1,a-k);
        b=min(n,b+k);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='Y'){
			if(left==right)
			    return 0;
			left=max(1LL,left-k);
			right=min(mid+k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
		if(right-left<4*k){
			long long gas=rand()%(right-left)+left;
			printf("%lld %lld\n",gas,gas);
			fflush(stdout);
			scanf("%s",&ans);
			if(ans[0]=='Y')
			    return 0;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='Y'){
			if(left==right)
			    return 0;
			left=max(1LL,left-k);
			right=min(mid+k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
		int tr=4*k;
		if(right-left<4*k){
			while(tr--){
				long long gas=rand()%(right-left)+left;
				printf("%lld %lld\n",gas,gas);
				fflush(stdout);
				scanf("%s",&ans);
				if(ans[0]=='Y')
				    return 0;
			}
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='Y'){
			if(left==right)
			    return 0;
			left=max(1LL,left-k);
			right=min(mid+k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
		if(right-left<=4*k){
			long long gas=rand()%(right-left)+left;
			printf("%lld %lld\n",gas,gas);
			fflush(stdout);
			scanf("%s",&ans);
			if(ans[0]=='Y')
			    return 0;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='Y'){
			if(left==right)
			    return 0;
			left=max(1LL,left-2*k);
			right=min(mid+2*k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
		while(right-left<4*k){
			long long gas=rand()%(right-left)+left;
			printf("%lld %lld\n",gas,gas);
			fflush(stdout);
			scanf("%s",&ans);
			if(ans[0]=='Y')
			    return 0;
			left=max(left-k,1LL);
			right=min(right+k,n);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='Y'){
			if(mid-left<4*k){
				long long gas=rand()%(right-left)+left;
				printf("%lld %lld\n",gas,gas);
				fflush(stdout);
				scanf("%s",&ans);
				if(ans[0]=='Y')
				    return 0;
			}
			if(left==right)
			    return 0;
			left=max(1LL,left-2*k);
			right=min(mid+2*k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='Y'){
			if(left==right)
			    return 0;
			left=max(1LL,left-2*k);
			right=min(mid+2*k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
		while(right-left<5*k){
			long long gas=rand()%(right-left)+left;
			printf("%lld %lld\n",gas,gas);
			fflush(stdout);
			scanf("%s",&ans);
			if(ans[0]=='Y')
			    return 0;
			left=max(left-k,1LL);
			right=min(right+k,n);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='Y'){
			if(left==right)
			    return 0;
			left=max(1LL,left-k);
			right=min(mid+k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
		while(right-left<5*k){
			long long gas=rand()%(right-left)+left;
			printf("%lld %lld\n",gas,gas);
			fflush(stdout);
			scanf("%s",&ans);
			if(ans[0]=='Y')
			    return 0;
			left=max(left-k,1LL);
			right=min(right+k,n);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='B')
		    return 0;
		if(ans[0]=='Y'){
			if(left==right)
			    return 0;
			left=max(1LL,left-k);
			right=min(mid+k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
		while(right-left<5*k){
			long long gas=rand()%(right-left+1)+left;
			printf("%lld %lld\n",gas,gas);
			fflush(stdout);
			scanf("%s",&ans);
			if(ans[0]=='Y')
			    return 0;
			left=max(left-k,1LL);
			right=min(right+k,n);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='Y'){
			if(left==right)
			    return 0;
			if(mid-left<4*k){
				long long gas=rand()%(right-left)+left;
				printf("%lld %lld\n",gas,gas);
				fflush(stdout);
				scanf("%s",&ans);
				if(ans[0]=='Y')
				    return 0;
			}
			left=max(1LL,left-2*k);
			right=min(mid+2*k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='Y'){
			if(left==right)
			    return 0;
			left=max(1LL,left-k);
			right=min(mid+k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
		int tr=4*k;
		while(tr--){
			if(right-left<4*k){
				long long gas=rand()%(right-left)+left;
				printf("%lld %lld\n",gas,gas);
				fflush(stdout);
				scanf("%s",&ans);
				if(ans[0]=='Y')
				    return 0;
			}
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='B')
		    return 0;
		if(ans[0]=='Y'){
			if(left==right)
			    return 0;
			left=max(1LL,left-k);
			right=min(mid+k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
		while(right-left<4*k){
			long long gas=rand()%(right-left)+left;
			printf("%lld %lld\n",gas,gas);
			fflush(stdout);
			scanf("%s",&ans);
			if(ans[0]=='Y')
			    return 0;
			left=max(left-k,1LL);
			right=min(right+k,n);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <string>
#define pi acos(-1.0)
using namespace std;

const int MAX=1e5+5;
long long n;
int k;
char ans[MAX];

int main(){

	srand(time(NULL));
	scanf("%lld%d",&n,&k);
	long long mid,left=1,right=n;
	while(left<=right){
		mid=left+(right-left)/2;
		printf("%lld %lld\n",left,mid);
		fflush(stdout);
		scanf("%s",&ans);
		if(ans[0]=='B')
		    return 0;
		if(ans[0]=='Y'){
			if(left==right)
			    return 0;
			left=max(1LL,left-k);
			right=min(mid+k,n);
		}
		else{
		    left=max(mid+1-k,1LL);
			right=min(right+k,n);
		}
		while(right-left<5*k){
			long long gas=rand()%(right-left)+left;
			printf("%lld %lld\n",gas,gas);
			fflush(stdout);
			scanf("%s",&ans);
			if(ans[0]=='Y')
			    return 0;
			left=max(left-k,1LL);
			right=min(right+k,n);
		}
	}
	return 0;
}


/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 05-Sep-2018 16:00:07
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;

pair <int, int> p[10];

inline int sq(int x) {
    return x * x;
}

inline int dist(int i, int j) {
    int x1 = p[i].first, y1 = p[i].second;
    int x2 = p[j].first, y2 = p[j].second;
    return sq(x1 - x2) + sq(y1 - y2);
}

inline bool isRightAngledTriangle(int i, int j, int k) {
    return dist(i, j) + dist(j, k) == dist(i, k);
}

inline bool isSquare(vector <int> &S) {
    bool ok = true;
    S.push_back(S[0]), S.push_back(S[1]);
    FOR (i, 1, 3) ok &= dist(S[i - 1], S[i]) == dist(S[i], S[i + 1]);
    FOR (i, 0, 3) ok &= isRightAngledTriangle(S[i], S[i + 1], S[i + 2]);
    return ok;
}

inline bool isRectangle(vector <int> &R) {
    bool ok = true;
    R.push_back(R[0]), R.push_back(R[1]);
    FOR (i, 0, 3) ok &= isRightAngledTriangle(S[i], S[i + 1], S[i + 2]);
    return ok;
}

int solve() {
    vector <int> idx;
    FOR (i, 1, 8) {
        idx.push_back(i);
        Int(p[i].first, p[i].second);
    }

    do {
        vector <int> S, R;
        FOR (i, 0, 3) S.push_back(idx[i]);
        FOR (i, 4, 7) R.push_back(idx[i]);

        if (isSquare(S) and isRectangle(R)) {
            printf("YES\n");
            printf("%d %d %d %d\n", idx[0], idx[1], idx[2], idx[3]);
            printf("%d %d %d %d\n", idx[4], idx[5], idx[6], idx[7]);

            return 0;
        }
    } while (next_permutation(all(idx)));

    printf("NO\n");

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}


/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 05-Sep-2018 23:50:05
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;

char replay[123];

bool ask(long long l, long long r) {
    printf("%lld %lld\n", l, r);
    fflush(stdout);
    scanf("%s", replay);
    if (l == r and replay[0] == 'Y') exit(0);
    return replay[0] == 'Y';
}

int solve() {
    long long n, k; Int(n, k);

    long long l = 1, r = n;
    FOR (i, 1, 4501) {
        long long range = r - l + 1;
        if (range > 4 * k + 3) {
            long long mid = l + r >> 1;
            if (ask(l, mid)) r = mid;
            else l = mid + 1;
        } else {
            long long x = l + rand() % range;
            ask(x, x);
        }

        l = max(1LL, l - k);
        r = min(n, r + k);
    }

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}


/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 05-Sep-2018 23:50:05
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

char replay[123];

bool ask(long long l, long long r) {
    printf("%lld %lld\n", l, r);
    fflush(stdout);
    scanf("%s", replay);
    if (l == r and replay[0] == 'Y') exit(0);
    return replay[0] == 'Y';
}

int solve() {
    long long n, k; Int(n, k);

    long long l = 1, r = n;
    FOR (i, 1, 4501) {
        long long range = r - l + 1;
        if (range > 4 * k + 3) {
            long long mid = l + r >> 1;
            if (ask(l, mid)) r = mid;
            else l = mid + 1;
        } else {
            long long x = l + rng() % range;
            ask(x, x);
        }

        l = max(1LL, l - k);
        r = min(n, r + k);
    }

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}


/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 05-Sep-2018 23:50:05
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;

char replay[123];

bool ask(long long l, long long r) {
    printf("%lld %lld\n", l, r);
    fflush(stdout);
    scanf("%s", replay);
    if (l == r and replay[0] == 'Y') exit(0);
    return replay[0] == 'Y';
}

int solve() {
    long long n, k; Int(n, k);

    long long l = 1, r = n;
    FOR (i, 1, 4501) {
        long long range = r - l + 1;
        if (range > 50) {
            long long mid = l + r >> 1;
            if (ask(l, mid)) r = mid;
            else l = mid + 1;
        } else {
            long long x = l + (rand() % range);
            ask(x, x);
        }

        l = max(1LL, l - k);
        r = min(n, r + k);
    }

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}


/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 05-Sep-2018 23:50:05
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;

char replay[123];

long long myrand(long long x) {
    long long t = rand() % x;
    t = (t * RAND_MAX + rand()) % x;
    return t;
}

bool ask(long long l, long long r) {
    printf("%lld %lld\n", l, r);
    fflush(stdout);
    scanf("%s", replay);
    if (l == r and replay[0] == 'Y') exit(0);
    return replay[0] == 'Y';
}

int solve() {
    long long n, k; Int(n, k);

    long long l = 1, r = n;
    FOR (i, 1, 4501) {
        long long range = r - l + 1;
        if (range > 4 * k + 3) {
            long long mid = l + r >> 1;
            if (ask(l, mid)) r = mid;
            else l = mid + 1;
        } else {
            long long x = l + myrand(range);
            ask(x, x);
        }

        l = max(1LL, l - k);
        r = min(n, r + k);
    }

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}


/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 05-Sep-2018 23:50:05
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;

char replay[123];

void ask(long long l, long long r) {
    printf("%lld %lld\n", l, r);
    fflush(stdout);
}

int solve() {
    long long n, k; Int(n, k);

    long long l = 1, r = n;
    FOR (i, 1, 4501) {
        long long mid = l + r >> 1;
        ask(l, mid);
        scanf("%s", replay);
        if (l == r and replay[0] == 'Y') break;
        long long ll, rr;
        if (replay[0] == 'Y') {
            ll = max(1LL, l - k);
            rr = min(n, mid + k);
        } else if (replay[0] == 'B') {
            ++mid;
            ll = max(1LL, mid - k);
            rr = min(n, r + k);
        } else break;

        if (l == ll and r == rr) {
            if (ll != 1) --ll;
            else if (rr != n) ++rr;
        }
        l = ll, r = rr;
    }

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}


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

int query(ll l, ll r) {
    fflush(stdout);
    cout << l << ' ' << r << endl;
    string s;
    cin >> s;
    if (s[0] == 'Y') return 1;
    if (s[0] == 'N') return 0;
    return -1;
}

int main() {
    srand(time(NULL));
    ll n, k;
    cin >> n >> k;
    ll l = 1, r = n;
    while (l <= r) {
        if (r - l + 1 <= 45) {
            int i = l + rand() % (r - l + 1);
            if (query(i, i) == 1) {
                return 0;
            }
            l = max(1ll, l - k);
            r = min(n, r + k);
        }
        ll m = (l + r) >> 1;
        int x = query(l, m);
        if (l == m && x == 1) {
            return 0;
        }
        if (x < 0) {
            return 0;
        }
        if (x == 1) {
            r = m;
        } else {
            l = m;
        }
        l = max(1ll, l - k);
        r = min(n, r + k);
    }
}


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

int query(ll l, ll r) {
    fflush(stdout);
    cout << l << ' ' << r << endl;
    string s;
    cin >> s;
    if (s[0] == 'Y') return 1;
    if (s[0] == 'N') return 0;
    return -1;
}

int main() {
    ll n, k;
    cin >> n >> k;
    ll l = 1, r = n;
    while (l <= r) {
        if (r - l + 1 < 4 * k) {
            if (query(l, l) == 1) {
                return 0;
            }
            l = max(1ll, l - k + 1);
            r = min(n, r + k);
        }
        ll m = (l + r) >> 1;
        int x = query(l, m);
        if (l == m && x == 1) {
            return 0;
        }
        int y = query(m, r);
        if (m == r && y == 1) {
            return 0;
        }
        if (x < 0 || y < 0) {
            return 0;
        }
        if (x == 1) {
            r = m;
        } else {
            l = m;
        }
        l = max(1ll, l - k);
        r = min(n, r + k);
    }
}


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

int query(ll l, ll r) {
    fflush(stdout);
    cout << l << ' ' << r << endl;
    string s;
    cin >> s;
    if (s[0] == 'Y') return 1;
    if (s[0] == 'N') return 0;
    return -1;
}

int main() {
    srand(time(NULL));
    ll n, k;
    cin >> n >> k;
    ll l = 1, r = n;
    while (l <= r) {
        if (r - l + 1 < 4 * k + 2) {
            int i = l + rand() % (r - l + 1);
            if (query(i, i) == 1) {
                return 0;
            }
            l = max(1ll, l - k);
            r = min(n, r + k);
        }
        ll m = (l + r) >> 1;
        int x = query(l, m);
        if (l == m && x == 1) {
            return 0;
        }
        if (x < 0) {
            return 0;
        }
        if (x == 1) {
            r = m;
        } else {
            l = m;
        }
        l = max(1ll, l - k);
        r = min(n, r + k);
    }
}


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

ll nextInt() {
    return rand() << 1 + rand() % 2;
}

ll nextLong(ll n) {
    return abs((nextInt() << 47) + (nextInt() << 31) + (nextInt() << 15) + rand());
}

int query(ll l, ll r) {
    fflush(stdout);
    cout << l << ' ' << r << endl;
    string s;
    cin >> s;
    if (s[0] == 'Y') return 1;
    if (s[0] == 'N') return 0;
    return -1;
}

int main() {
    srand(time(NULL));
    ll n, k;
    cin >> n >> k;
    ll l = 1, r = n;
    while (l <= r) {
        if (r - l + 1 < 40) {
            ll i = l + rand() % (r - l + 1);
            if (query(i, i) == 1) {
                return 0;
            }
            l = max(1ll, l - k);
            r = min(n, r + k);
        }
        ll m = (l + r) >> 1;
        int x = query(l, m);
        if (l == m && x == 1) {
            return 0;
        }
        if (x < 0) {
            return 0;
        }
        if (x == 1) {
            r = m;
        } else {
            l = m + 1;
        }
        l = max(1ll, l - k);
        r = min(n, r + k);
    }
}


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

int query(ll l, ll r) {
    fflush(stdout);
    cout << l << ' ' << r << endl;
    string s;
    cin >> s;
    if (s[0] == 'Y') return 1;
    if (s[0] == 'N') return 0;
    return -1;
}

int main() {
    srand(time(NULL));
    ll n, k;
    cin >> n >> k;
    ll l = 1, r = n;
    while (l <= r) {
        if (l == r && query(l, r) == 1) {
            return 0;
        }
        if (r - l + 1 <= 4 * k) {
            int y = l + rand() % (r - l + 1);
            if (query(y, y) == 1) {
                return 0;
            }
            l = max(1ll, l - k);
            r = min(n, r + k);
        }
        ll m = (l + r) >> 1;
        int x = query(l, m);
        if (l == m && x == 1) {
            return 0;
        }
        int y = query(m, r);
        if (m == r && y == 1) {
            return 0;
        }
        if (x < 0 || y < 0) {
            return 0;
        }
        if (x == 1) {
            r = m;
        } else {
            l = m;
        }
        l = max(1ll, l - k);
        r = min(n, r + k);
    }
}


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

int query(ll l, ll r) {
    fflush(stdout);
    cout << l << ' ' << r << endl;
    string s;
    cin >> s;
    if (s[0] == 'Y') return 1;
    if (s[0] == 'N') return 0;
    return -1;
}

int main() {
    ll n, k;
    cin >> n >> k;
    ll l = 1, r = n;
    while (l < r) {
        if (r - l + 1 <= 4 * k) {
            if (query(l, l) == 1) {
                return 0;
            }
            l = max(1ll, l - k);
            r = min(n, r + k);
        }
        ll m = (l + r) >> 1;
        int x = query(l, m);
        int y = query(m, r);
        if (x < 0 || y < 0) {
            return 0;
        }
        if (x == 1) {
            r = m;
        } else {
            l = m;
        }
        l = max(1ll, l - k);
        r = min(n, r + k);
    }
}


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

ll nextInt() {
    return rand() << 1 + rand() % 2;
}

ll nextLong(ll n) {
    return abs((nextInt() << 47) + (nextInt() << 31) + (nextInt() << 15) + rand());
}

int query(ll l, ll r) {
    fflush(stdout);
    cout << l << ' ' << r << endl;
    string s;
    cin >> s;
    if (s[0] == 'Y') return 1;
    if (s[0] == 'N') return 0;
    return -1;
}

int main() {
    srand(time(NULL));
    ll n, k;
    cin >> n >> k;
    ll l = 1, r = n;
    while (l <= r) {
        if (r - l < 40) {
            ll i = l + rand() % (r - l + 1);
            if (query(i, i) == 1) {
                return 0;
            }
            l = max(1ll, l - k);
            r = min(n, r + k);
        }
        ll m = (l + r) >> 1;
        int x = query(l, m);
        if (l == m && x == 1) {
            return 0;
        }
        if (x < 0) {
            return 0;
        }
        if (x == 1) {
            r = m;
        } else {
            l = m + 1;
        }
        l = max(1ll, l - k);
        r = min(n, r + k);
    }
}


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

ll nextInt() {
    return rand() << 1 + rand() % 2;
}

ll nextLong(ll n) {
    return abs((nextInt() << 47) + (nextInt() << 31) + (nextInt() << 15) + rand());
}

int query(ll l, ll r) {
    fflush(stdout);
    cout << l << ' ' << r << endl;
    string s;
    cin >> s;
    if (s[0] == 'Y') return 1;
    if (s[0] == 'N') return 0;
    return -1;
}

int main() {
    srand(time(NULL));
    ll n, k;
    cin >> n >> k;
    ll l = 1, r = n;
    while (l <= r) {
        if (r - l < 50) {
            ll i = l + rand() % (r - l + 1);
            if (query(i, i) == 1) {
                return 0;
            }
            l = max(1ll, l - k);
            r = min(n, r + k);
        }
        ll m = (l + r) >> 1;
        int x = query(l, m);
        if (l == m && x == 1) {
            return 0;
        }
        if (x < 0) {
            return 0;
        }
        if (x == 1) {
            r = m;
        } else {
            l = m + 1;
        }
        l = max(1ll, l - k);
        r = min(n, r + k);
    }
}


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

int query(ll l, ll r) {
    fflush(stdout);
    cout << l << ' ' << r << endl;
    string s;
    cin >> s;
    if (s[0] == 'Y') return 1;
    if (s[0] == 'N') return 0;
    return -1;
}

int main() {
    srand(time(NULL));
    ll n, k;
    cin >> n >> k;
    ll l = 1, r = n;
    while (l <= r) {
        if (r - l + 1 < 45) {
            int i = l + rand() % (r - l + 1);
            if (query(i, i) == 1) {
                return 0;
            }
            l = max(1ll, l - k);
            r = min(n, r + k);
        }
        ll m = (l + r) >> 1;
        int x = query(l, m);
        if (l == m && x == 1) {
            return 0;
        }
        if (x < 0) {
            return 0;
        }
        if (x == 1) {
            r = m;
        } else {
            l = m;
        }
        l = max(1ll, l - k);
        r = min(n, r + k);
    }
}


#include <bits/stdc++.h>

using namespace std;

long long n, k;

int main()
{
    srand(time(NULL));
	cin >> n >> k;
	long long l = 1, r = n;
	string res;
	while (true) {
		if (r-l <= 45) {
			long long ans = l + rand() % (r-l+1);
			printf("%lld %lld\n", ans, ans);

			fflush(stdout);
			//cout << ans << " " << ans << "\n";
			cin >> res;
			if (res == "Yes") {
				break;
			}
			else if (res == "No") {
				l = max(1LL, l-k);
				r = min(n, r+k);
			}
			else {
				break;
			}
		}
		else {
			long long mid = (l+r)/2;
			printf("%lld %lld\n", l, mid);
			//cout << l << " " << mid << "\n";
			fflush(stdout);
			cin >> res;
			if (res == "Yes") {
				if (l == mid) {
					break;
				}
				else {
					l = max(1LL, l-k);
					r = min(n, mid+k);
				}
			}
			else if (res == "No") {
				l = max(1LL, mid+1-k);
				r = min(n, r+k);
			}
			else {
				break;
			}
		}
	}
	return 0;
}


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

int query(ll l, ll r) {
    fflush(stdout);
    cout << l << ' ' << r << endl;
    string s;
    cin >> s;
    if (s[0] == 'Y') return 1;
    if (s[0] == 'N') return 0;
    return -1;
}

int main() {
    srand(time(NULL));
    ll n, k;
    cin >> n >> k;
    ll l = 1, r = n;
    while (l <= r) {
        if (r - l + 1 < 45) {
            int i = l + rand() % (r - l + 1);
            if (query(i, i) == 1) {
                return 0;
            }
            l = max(1ll, l - k);
            r = min(n, r + k);
        }
        ll m = (l + r) >> 1;
        int x = query(l, m);
        if (l == m && x == 1) {
            return 0;
        }
        if (x < 0) {
            return 0;
        }
        if (x == 1) {
            r = m;
        } else {
            l = m + 1;
        }
        l = max(1ll, l - k);
        r = min(n, r + k);
    }
}


/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <utility>
#include <set>
#include <unordered_set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>
#include <complex>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

int f(string &s) //convert to binary
{
    bitset<12> magic(s);
    return magic.to_ulong();
}

int c[12];
int cnt[1<<12];
bool vis[1<<12];
int dp[101][1<<12];

int n, m, q;

void solve(int msk)
{
    vis[msk] = 1;
    for (int i = 0; i < (1 << n); i++)
    {
        if (cnt[i] == 0) continue;
        int x = 0;
        for (int j = 0; j < n; j++)
        {
            if ((msk & (1<<j)) == (i & (1<<j))) x += c[j];
            if (x > 100) break;
        }
        if (x <= 100) dp[x][msk] += cnt[i];
    }
    for (int i = 1; i <= 100; i++) dp[i][msk] += dp[i-1][msk];
}

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    ios::sync_with_stdio(0); cin.tie(0);

    cin >> n >> m >> q;

    for (int i = n-1; i >= 0; i--) cin >> c[i];

    while (m--)
    {
        string s; cin >> s;
        cnt[f(s)]++;
    }

    while (q--)
    {
        string t; int k;
        cin >> t >> k;
        int msk = f(t);
        if (!vis[msk]) solve(msk);
        cout << dp[k][msk] << '\n';
    }

    return 0;

}


//Hello
#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
    #include "/home/chaman/Desktop/cpp/debug.h"
#else
    #define debug(args...)
    #define DBG(x...)
#endif
typedef     long long int                        ll;
typedef     long double                          ld;
typedef     vector<ll>                           vi;
typedef     pair<ll,ll>                          pii;
typedef     vector<pii>                          vpi;
typedef     vector<vi>                           vvi;
typedef     map<ll,ll>                           mii;
typedef     map<char,ll>                         mci;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pii>                  pqii;
typedef     priority_queue<ll,vi,greater<ll>>    pqmini;
typedef     priority_queue<pii,vpi,greater<pii>> pqminpi;

#define     fi              first
#define     se              second
#define     sz(a)           (ll)((a).size())
#define     rep(i,n)        for(ll i=0;i<n;i++)
#define     repA(i,a,n)     for(auto i=a;i<=n;i++)
#define     repD(i, a, n)   for(auto i = a; i >= (n); --i)
#define     trav(a, x)      for(auto& a : x)
#define     all(x)          x.begin(), x.end()
#define     fill(a)         memset(a, 0, sizeof (a))
#define     pb              push_back
#define     MOD             1000000007
#define     PI              3.14159265359
#define     EULER           2.7182818284

//////////////////////////////////////////////////////////////////////
vi cnt;
vi w(20,0);
ll btod(string s){
    ll k=0;
    ll l=s.length();
    repD(i,l-1,0){
        k+=(s[i]-'0')*(1<<(l-1-i));
    }
    return k;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream in("input.txt");
    // streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
    // ofstream out("output.txt");
    // streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
    cout.precision(20);
    ll n,m,q;
    cin>>n>>m>>q;
    rep(i,n){
        cin>>w[i];
    }
    ll ss = (1<<(n));
    cnt = vi(ss+1,0);
    string s;
    rep(i,m){
        cin>>s;
        ll t=btod(s);
        cnt[t]++;
    }
    DBG(w);
    vvi dp(ss,vi(120,0));
    rep(i,ss){
        ll p=0;
        rep(j,ss){
            if(!cnt[j]){continue;}
            ll c =0;
            rep(ii,n){
                if(ii>n-1)break;
                if((i&(1<<ii))==(j&(1<<ii)))c+=w[n-1-ii];
                if(c>100)break;
            }
            if(c<102)dp[i][c]+=cnt[j];
        }
    }
    vi vis(ss,0);
    rep(i,q){
        cin>>s;
        ll w1;
        cin>>w1;
        ll k = btod(s);
        if(!vis[k]){
            vis[k]=1;
            repA(j,1,100){
                dp[k][j]+=dp[k][j-1];
            }
        }
        cout<<dp[k][w1]<<"\n";
    }

    debug("\nRuntime = " + to_string((ld)clock()/(ld)CLOCKS_PER_SEC));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
    #include "/home/chaman/Desktop/cpp/debug.h"
#else
    #define debug(args...)
    #define DBG(x...)
#endif
typedef     long long int                        ll;
typedef     long double                          ld;
typedef     vector<ll>                           vi;
typedef     pair<ll,ll>                          pii;
typedef     vector<pii>                          vpi;
typedef     vector<vi>                           vvi;
typedef     map<ll,ll>                           mii;
typedef     map<char,ll>                         mci;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pii>                  pqii;
typedef     priority_queue<ll,vi,greater<ll>>    pqmini;
typedef     priority_queue<pii,vpi,greater<pii>> pqminpi;

#define     fi              first
#define     se              second
#define     sz(a)           (ll)((a).size())
#define     rep(i,n)        for(ll i=0;i<n;i++)
#define     repA(i,a,n)     for(auto i=a;i<=n;i++)
#define     repD(i, a, n)   for(auto i = a; i >= (n); --i)
#define     trav(a, x)      for(auto& a : x)
#define     all(x)          x.begin(), x.end()
#define     fill(a)         memset(a, 0, sizeof (a))
#define     pb              push_back
#define     MOD             1000000007
#define     PI              3.14159265359
#define     EULER           2.7182818284

//////////////////////////////////////////////////////////////////////
vi cnt;
vi w(20,0);
ll btod(string s){
    ll k=0;
    ll l=s.length();
    repD(i,l-1,0){
        k+=(s[i]-'0')*(1<<(l-1-i));
    }
    return k;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream in("input.txt");
    // streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
    // ofstream out("output.txt");
    // streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
    cout.precision(20);
    ll n,m,q;
    cin>>n>>m>>q;
    rep(i,n){
        cin>>w[i];
    }
    ll ss = (1<<(n));
    cnt = vi(ss+1,0);
    string s;
    rep(i,m){
        cin>>s;
        ll t=btod(s);
        cnt[t]++;
    }
    DBG(w);
    vvi dp(ss,vi(120,0));
    rep(i,ss){
        ll p=0;
        rep(j,ss){
            if(!cnt[j]){continue;}
            ll c =0;
            rep(ii,n){
                if(ii>n-1)break;
                if((i&(1<<ii))==(j&(1<<ii)))c+=w[n-1-ii];
                if(c>100)break;
            }
            if(c<102)dp[i][c]+=cnt[j];
        }
    }
    vi vis(ss,0);
    rep(i,q){
        cin>>s;
        ll w1;
        cin>>w1;
        ll k = btod(s);
        if(!vis[k]){
            vis[k]=1;
            repA(j,1,100){
                dp[k][j]+=dp[k][j-1];
            }
        }
        cout<<dp[k][w1]<<"\n";
    }

    debug("\nRuntime = " + to_string((ld)clock()/(ld)CLOCKS_PER_SEC));
    return 0;
}


//Actual Soln - https://codeforces.com/contest/1017/submission/41374761

#include <bits/stdc++.h>

using namespace std;

typedef complex<int> point;
#define dp(a, b) ((conj(a) * b).real())
#define cp(a, b) ((conj(a) * b).imag())
#define angle(a) (atan2(a.imag(), a.real()))
#define rotate0(a, angle) (a * exp(point(0, angle)))
#define length(a) (hypot(a.imag(), a.real()))
#define rotateAr(a, angle, around) (rotate0(((a) - (around)),(angle)) + around)
#define reflect(a, m) (conj((a)/(m)) * (m))
#define normalize(a) ((a) / length(a));
typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define per(i, start, end) for(int i = (int)start-1; i >= end; --i)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
const double PI = 3.14159265358979323846;
const double eps = (1e-8);

int n, m, q;
int freq[5000];
int ans[5000][110] = {0};
int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
////    freopen("facebook.txt", "w", stdout);
//#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> q;
    vector<int> w(15);
    rep(i, 0, n)
    {
        cin >> w[i];
    }
    rep(i, 0, m)
    {
        string s;
        cin >> s;
        int id = 0;
        rep(j,0,15)
        {
            if (s[j] == '1')
            {
                id |= (1<<j);
            }

        }
        freq[id]++;
    }
    int N = (1<<n);
    vector<pair<int , int> > v;
    for (int msk2 = 0; msk2 < N; ++msk2)
    {
        if (freq[msk2])
        {
            v.pb({msk2, freq[msk2]});
        }
    }

    for (int msk1 = 0; msk1 < N; ++msk1)
    {
        for (int k = 0; k < sz(v); ++k)
        {
            int msk2 = v[k].F;
            int sum = 0;
            for (int j = 0; j < 15; ++j)
            {
                if ( ((1<<j)&msk1) == ((1<<j)&msk2))
                    sum = sum + w[j];
                if (sum > 100)
                    break;
            }
            if (sum <= 100)
                ans[msk1][sum] += v[k].S;
        }
        for (int i = 1; i <= 100; ++i)
            ans[msk1][i] += ans[msk1][i-1];
    }
    rep(i, 0, q)
    {
        string query;
        int maxSum;
        cin >> query >> maxSum;
        int qID = 0;
        rep(j,0,n)
        {
            if (query[j] == '1')
                qID |= (1<<j);
        }
        cout << ans[qID][maxSum] << endl;
    }
    return 0;
}


//Actual Soln - https://codeforces.com/contest/1017/submission/41374761

#include <bits/stdc++.h>

using namespace std;

typedef complex<int> point;
#define dp(a, b) ((conj(a) * b).real())
#define cp(a, b) ((conj(a) * b).imag())
#define angle(a) (atan2(a.imag(), a.real()))
#define rotate0(a, angle) (a * exp(point(0, angle)))
#define length(a) (hypot(a.imag(), a.real()))
#define rotateAr(a, angle, around) (rotate0(((a) - (around)),(angle)) + around)
#define reflect(a, m) (conj((a)/(m)) * (m))
#define normalize(a) ((a) / length(a));
typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define per(i, start, end) for(int i = (int)start-1; i >= end; --i)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
const double PI = 3.14159265358979323846;
const double eps = (1e-8);

int n, m, q;
int freq[5000];
int ans[5000][110] = {0};
int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
////    freopen("facebook.txt", "w", stdout);
//#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> q;
    vector<int> w(15);
    rep(i, 0, n)
    {
        cin >> w[i];
    }
    rep(i, 0, m)
    {
        string s;
        cin >> s;
        int id = 0;
        rep(j,0,15)
        {
            if (s[j] == '1')
            {
                id |= (1<<j);
            }

        }
        freq[id]++;
    }
    int N = (1<<n);
    vector<pair<int , int> > v;
    for (int msk2 = 0; msk2 < N; ++msk2)
    {
        if (freq[msk2])
        {
            v.pb({msk2, freq[msk2]});
        }
    }

    for (int msk1 = 0; msk1 < N; ++msk1)
    {
        for (int k = 0; k < sz(v); ++k)
        {
            int msk2 = v[k].F;
            int sum = 0;
            for (int j = 0; j < 15; ++j)
            {
                if ( ((1<<j)&msk1) == ((1<<j)&msk2))
                    sum = sum + w[j];
                if (sum > 100)
                    break;
            }
            if (sum <= 100)
                ans[msk1][sum] += v[k].S;
        }
        for (int i = 1; i <= 100; ++i)
            ans[msk1][i] += ans[msk1][i-1];
    }
    rep(i, 0, q)
    {
        string query;
        int maxSum;
        cin >> query >> maxSum;
        int qID = 0;
        rep(j,0,15)
        {
            if (query[j] == '1')
                qID |= (1<<j);
        }
        cout << ans[qID][maxSum] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
    #include "/home/chaman/Desktop/cpp/debug.h"
#else
    #define debug(args...)
    #define DBG(x...)
#endif
typedef     long long int                        ll;
typedef     long double                          ld;
typedef     vector<ll>                           vi;
typedef     pair<ll,ll>                          pii;
typedef     vector<pii>                          vpi;
typedef     vector<vi>                           vvi;
typedef     map<ll,ll>                           mii;
typedef     map<char,ll>                         mci;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pii>                  pqii;
typedef     priority_queue<ll,vi,greater<ll>>    pqmini;
typedef     priority_queue<pii,vpi,greater<pii>> pqminpi;

#define     fi              first
#define     se              second
#define     sz(a)           (ll)((a).size())
#define     rep(i,n)        for(ll i=0;i<n;i++)
#define     repA(i,a,n)     for(auto i=a;i<=n;i++)
#define     repD(i, a, n)   for(auto i = a; i >= (n); --i)
#define     trav(a, x)      for(auto& a : x)
#define     all(x)          x.begin(), x.end()
#define     fill(a)         memset(a, 0, sizeof (a))
#define     pb              push_back
#define     MOD             1000000007
#define     PI              3.14159265359
#define     EULER           2.7182818284

//////////////////////////////////////////////////////////////////////
vi cnt;
vi w(20,0);
ll btod(string s){
    ll k=0;
    ll l=s.length();
    repD(i,l-1,0){
        k+=(s[i]-'0')*(1<<(l-1-i));
    }
    return k;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream in("input.txt");
    // streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
    // ofstream out("output.txt");
    // streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
    cout.precision(20);
    ll n,m,q;
    cin>>n>>m>>q;
    rep(i,n){
        cin>>w[i];
    }
    ll ss = (1<<(n));
    cnt = vi(ss+1,0);
    string s;
    rep(i,m){
        cin>>s;
        ll t=btod(s);
        cnt[t]++;
    }
    DBG(w);
    vvi dp(ss,vi(120,0));
    rep(i,ss){
        ll p=0;
        rep(j,ss){
            if(!cnt[j]){continue;}
            ll c =0;
            rep(ii,n){
                if(ii>n-1)break;
                if((i&(1<<ii))==(j&(1<<ii)))c+=w[n-1-ii];
                if(c>100)break;
            }
            if(c<102)dp[i][c]+=cnt[j];
        }
    }
    vi vis(ss,0);
    rep(i,q){
        cin>>s;
        ll w1;
        cin>>w1;
        ll k = btod(s);
        if(!vis[k]){
            vis[k]=1;
            repA(j,1,100){
                dp[k][j]+=dp[k][j-1];
            }
        }
        cout<<dp[k][w1]<<'\n';
    }

    debug("\nRuntime = " + to_string((ld)clock()/(ld)CLOCKS_PER_SEC));
    return 0;
}


//Actual Soln - https://codeforces.com/contest/1017/submission/41374761

#include <bits/stdc++.h>

using namespace std;

typedef complex<int> point;
#define dp(a, b) ((conj(a) * b).real())
#define cp(a, b) ((conj(a) * b).imag())
#define angle(a) (atan2(a.imag(), a.real()))
#define rotate0(a, angle) (a * exp(point(0, angle)))
#define length(a) (hypot(a.imag(), a.real()))
#define rotateAr(a, angle, around) (rotate0(((a) - (around)),(angle)) + around)
#define reflect(a, m) (conj((a)/(m)) * (m))
#define normalize(a) ((a) / length(a));
typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define per(i, start, end) for(int i = (int)start-1; i >= end; --i)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
const double PI = 3.14159265358979323846;
const double eps = (1e-8);

int n, m, q;
int freq[5000];
int ans[5000][110] = {0};
int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
////    freopen("facebook.txt", "w", stdout);
//#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> q;
    vector<int> w(15);
    rep(i, 0, n)
    {
        cin >> w[i];
    }
    rep(i, 0, m)
    {
        string s;
        cin >> s;
        int id = 0;
        rep(j,0,15)
        {
            if (s[j] == '1')
            {
                id |= (1<<j);
            }

        }
        freq[id]++;
    }
    int N = (1<<n);
    vector<pair<int , int> > v;
    for (int msk2 = 0; msk2 < N; ++msk2)
    {
        if (freq[msk2])
        {
            v.pb({msk2, freq[msk2]});
        }
    }

    for (int msk1 = 0; msk1 < N; ++msk1)
    {
        for (int k = 0; k < sz(v); ++k)
        {
            int msk2 = v[k].F;
            int sum = 0;
            for (int j = 0; j < n; ++j)
            {
                if ( ((1<<j)&msk1) == ((1<<j)&msk2))
                    sum = sum + w[j];
                if (sum > 100)
                    break;
            }
            if (sum <= 100)
                ans[msk1][sum] += v[k].S;
        }
        for (int i = 1; i <= 100; ++i)
            ans[msk1][i] += ans[msk1][i-1];
    }
    rep(i, 0, q)
    {
        string query;
        int maxSum;
        cin >> query >> maxSum;
        int qID = 0;
        rep(j,0,n)
        {
            if (query[j] == '1')
                qID |= (1<<j);
        }
        cout << ans[qID][maxSum] << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll powe(ll a,ll b)
{
	ll ans=1;
	while(b>0)
	{
		if(b&1)ans*=a;
		b=b>>1;
		a=a*a;
	}
	return ans;
}
ll dp[(1<<12)+2][105];
int main()
{
	ios_base::sync_with_stdio(false);
    ll n,m,q,p;
    cin>>n>>m>>q;
    ll w[n+5];
    ll A[(1<<n)+5]={0};
    ll B[(1<<n)+5]={0};
    for(int i=n-1;i>=0;i--)cin>>w[i];
    string s;
    set<ll>st;
    for(int i=0;i<m;i++)
      {
      	cin>>s;
      	ll num=0;
      	//cout<<s<<endl;
      	for(ll i=n-1;i>=0;i--)
      	   {
      	   	   if(s[i]=='1')
      	   	     {
      	   	       num+=(1<<(n-1-i));
				 }
		   }
		   st.insert(num);
		A[num]++;
	  }

	for(ll i=0;i<(1<<n);i++)
	{
	  ll sum=0;
		for(int j=0;j<n;j++)
		   {
		   	 if((1<<j)&i)
		   	   {
		   	   	sum+=w[j];
			   }
		   }
		B[i]=sum;
	}

	for(ll i=0;i<(1<<n);i++)
	  {
	  	for(set<ll>::iterator it =st.begin();it!=st.end();it++)
	  	  {
	  	  	ll num=*it;
			ll k=powe(2,n);
			if((k-(i^num)-1)<=100)
		   	dp[i][B[k-(i^num)-1]]=A[num];
		  }
		for(ll j=1;j<=100;j++)dp[i][j]+=dp[i][j-1];

	  }
    while(q--)
    {
    	cin>>s>>p;
    	ll num=0;
      	for(ll i=n-1;i>=0;i--)
      	   {
      	   	   if(s[i]=='1')
      	   	     {
      	   	       num+=(1<<(n-1-i));
				 }
		   }
		cout<<dp[num][p]<<endl;
	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll powe(ll a,ll b)
{
	ll ans=1;
	while(b>0)
	{
		if(b&1)ans*=a;
		b=b>>1;
		a=a*a;
	}
	return ans;
}
ll dp[(1<<12)+2][1205];
vector<pair<int,int> > Q;
int main()
{
	ios_base::sync_with_stdio(false);
    ll n,m,q,p;
    cin>>n>>m>>q;
    ll w[n+5];
    ll A[(1<<n)+5]={0};
    ll B[(1<<n)+5]={0};
    for(int i=n-1;i>=0;i--)cin>>w[i];
    string s;
    set<int>st;
    for(int i=0;i<m;i++)
      {
      	cin>>s;
      	ll num=0;
      	//cout<<s<<endl;
      	for(int i=n-1;i>=0;i--)
      	   {
      	   	   if(s[i]=='1')
      	   	     {
      	   	       num+=(1<<(n-1-i));
				 }
		   }
		   st.insert(num);
		A[num]++;
	  }

	for(int i=0;i<(1<<n);i++)
	{
	  ll sum=0;
		for(int j=0;j<n;j++)
		   {
		   	 if((1<<j)&i)
		   	   {
		   	   	sum+=w[j];
			   }
		   }
		B[i]=sum;
	}

	for(int i=0;i<(1<<n);i++)
	  {
	  	for(set<int>::iterator it =st.begin();it!=st.end();it++)
	  	  {
	  	  	ll num=*it;
			ll k=powe(2,n);
		   	dp[i][B[k-(i^num)-1]]=A[num];
		  }
		for(int j=1;j<=1200;j++)dp[i][j]+=dp[i][j-1];

	  }
    while(q--)
    {
    	cin>>s>>p;
    	ll num=0;
      	for(int i=n-1;i>=0;i--)
      	   {
      	   	   if(s[i]=='1')
      	   	     {
      	   	       num+=(1<<(n-1-i));
				 }
		   }
		cout<<dp[num][p]<<endl;
	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll powe(ll a,ll b)
{
	ll ans=1;
	while(b>0)
	{
		if(b&1)ans*=a;
		b=b>>1;
		a=a*a;
	}
	return ans;
}
vector<pair<int,int> > Q;
int main()
{
	ios_base::sync_with_stdio(false);
    ll n,m,q;
    cin>>n>>m>>q;
    ll w[n+5];
    ll A[(1<<n)+5]={0};
    ll B[(1<<n)+5]={0};
    for(int i=n-1;i>=0;i--)cin>>w[i];
    string s;
    set<int>st;
    st.insert(0);
    for(int i=0;i<m;i++)
      {
      	cin>>s;
      	ll num=0;
      	//cout<<s<<endl;
      	for(int i=n-1;i>=0;i--)
      	   {
      	   	   if(s[i]=='1')
      	   	     {
      	   	       num+=(1<<(n-1-i));
				 }
		   }
		   st.insert(num);
		A[num]++;
	  }
	  //for(int i=0;i<=(1<<n);i++)cout<<A[i]<<" ";
	  //cout<<endl;
	for(int i=1;i<(1<<n);i++)
	{
	  ll sum=0;
		for(int j=0;j<n;j++)
		   {
		   	 if((1<<j)&i)
		   	   {
		   	   	sum+=w[j];
			   }
		   }
		B[i]=sum;
	}
	//for(int i=0;i<=(1<<n);i++)cout<<B[i]<<" ";
	  //cout<<endl;
    ll p;
    set<int> D[(1<<n)+5];

    for(int i=0;i<q;i++)
       {
       	 cin>>s>>p;

       	 ll num=0;
      	 //cout<<s<<endl;
      	 for(int i=n-1;i>=0;i--)
      	   {
      	   	   if(s[i]=='1')
      	   	     {
      	   	       num+=(1<<(n-1-i));
				 }
		   }
		    Q.push_back(make_pair(num,p));
		  D[num].insert(p);
	   }

	ll dp[(1<<n)+2][101];
	for(set<int>::iterator it1=st.begin();it1!=st.end();it1++)
	  {
	  	for(set<int>::iterator it=D[*it1].begin();it!=D[*it1].end();it++)
	  	  {
	  	  	ll num=*it1;
				p=*it;
				ll ans=0,k=powe(2,n);
		     for(set<int>::iterator it2=st.begin();it2!=st.end();it2++)
		      {
		   	  //cout<<i<<" "<<num<<" "<<k-(i^num)-1<<" "<<B[k-1-(i^num)]<<endl;
		   	  ll l=*it2;
		   	  if(B[k-(l^num)-1]<=p)
		   	    ans+=A[l];
		       }
		     dp[*it1][*it]=ans;
		     //cout<<i<<" "<<j<<" "<<ans<<endl;
		  }

	  }
  	/*while(q--)
	{
	     	cin>>s>>p;
		ll num=0;
      	//cout<<s<<endl;
      	for(int i=n-1;i>=0;i--)
      	   {
      	   	   if(s[i]=='1')
      	   	     {
      	   	       num+=(1<<(n-1-i));
				 }
		   }
		   cout<<dp[num][p]<<endl;
		ll ans=0,k=powe(2,n);
		for(ll i=0;i<=(1LL<<n)-1;i++)
		   {
		   	  //cout<<i<<" "<<num<<" "<<k-(i^num)-1<<" "<<B[k-1-(i^num)]<<endl;
		   	  if(B[k-(i^num)-1]<=p)
		   	    ans+=A[i];
		   }
		cout<<ans<<endl;
	} */
	for(int i=0;i<q;i++)
	   {
	   	cout<<dp[Q[i].first][Q[i].second]<<endl;
	   }

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll powe(ll a,ll b)
{
	ll ans=1;
	while(b>0)
	{
		if(b&1)ans*=a;
		b=b>>1;
		a=a*a;
	}
	return ans;
}
ll dp[(1<<12)+2][105];
int main()
{
	ios_base::sync_with_stdio(false);
    ll n,m,q,p;
    cin>>n>>m>>q;
    ll w[n+5];
    ll A[(1<<n)+5]={0};
    ll B[(1<<n)+5]={0};
    for(int i=n-1;i>=0;i--)cin>>w[i];
    string s;
    set<ll>st;
    for(int i=0;i<m;i++)
      {
      	cin>>s;
      	ll num=0;
      	//cout<<s<<endl;
      	for(ll i=n-1;i>=0;i--)
      	   {
      	   	   if(s[i]=='1')
      	   	     {
      	   	       num+=(1<<(n-1-i));
				 }
		   }
		   st.insert(num);
		A[num]++;
	  }

	for(ll i=0;i<(1<<n);i++)
	{
	  ll sum=0;
		for(int j=0;j<n;j++)
		   {
		   	 if((1<<j)&i)
		   	   {
		   	   	sum+=w[j];
			   }
		   }
		B[i]=sum;
	}
	for(ll i=0;i<(1<<n);i++)
	  {
	  	for(set<ll>::iterator it =st.begin();it!=st.end();it++)
	  	  {
	  	  	ll num=*it;
			ll k=powe(2,n);
			if(B[(k-(i^num)-1)]<=100)
		   	dp[i][B[k-(i^num)-1]]=A[num];
		  }
		for(ll j=1;j<=100;j++)dp[i][j]+=dp[i][j-1];

	  }
    while(q--)
    {
    	cin>>s>>p;
    	ll num=0;
      	for(ll i=n-1;i>=0;i--)
      	   {
      	   	   if(s[i]=='1')
      	   	     {
      	   	       num+=(1<<(n-1-i));
				 }
		   }
		cout<<dp[num][p]<<endl;
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int sum[4500][110],tot[4500],w[20],W[4500];
int main(){
      int n,m,q,i,j,k;
      scanf("%d%d%d",&n,&m,&q);
      for(i=0;i<n;i++)scanf("%d",&w[i]);
      for(i=1;i<=m;i++){
      	int x=0;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	tot[x]++;
      }
      for(i=0;i<(1<<n);i++)
        for(j=0;j<n;j++)
          if(!(i&(1<<j)))W[i]+=w[j];
      for(i=0;i<(1<<n);i++)
        for(j=0;j<(1<<n);j++)
          if(W[i^j]<=100)sum[i][W[i^j]]+=tot[j];
      for(i=0;i<(1<<n);i++)
        for(j=1;j<=100;j++)
          sum[i][j]+=sum[i][j-1];
      for(i=1;i<=q;i++){
      	int x=0,all;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	scanf("%d",&all);
      	printf("%d\n",sum[x][all]);
      }
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int sum[4500][110],tot[4500],w[20];
int main(){
      int n,m,q,i,j,k;
      scanf("%d%d%d",&n,&m,&q);
      for(i=0;i<n;i++)scanf("%d",&w[i]);
      for(i=1;i<=m;i++){
      	int x=0;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	tot[x]++;
      }
      for(i=0;i<(1<<n);i++)
        for(j=0;j<(1<<n);j++){
          int W=0;
          for(k=0;k<n;k++)
            if(((i^j)&(1<<k))==0)W+=w[k];
          if(W<=100)sum[i][W]=tot[j];
        }
      for(i=0;i<(1<<n);i++)
        for(j=1;j<=100;j++)
          sum[i][j]+=sum[i][j-1];
      for(i=1;i<=q;i++){
      	int x=0,all;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	scanf("%d",&all);
      	printf("%d\n",sum[x][all]);
      }
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int sum[4500][110],tot[4500],w[20];
int main(){
      int n,m,q,i,j,k;
      scanf("%d%d%d",&n,&m,&q);
      for(i=0;i<n;i++)scanf("%d",&w[i]);
      for(i=1;i<=m;i++){
      	int x=0;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	tot[x]++;
      }
      for(i=0;i<(1<<n);i++)
        for(j=0;j<(1<<n);j++){
          int W=0;
          for(k=0;k<n;k++)
            if(((i^j)&(1<<k))==0)W+=w[k];
          if(W<=100)sum[i][W]+=tot[j];
        }
      for(i=0;i<(1<<n);i++)
        for(j=1;j<=100;j++)
          sum[i][j]+=sum[i][j-1];
      for(i=1;i<=q;i++){
      	int x=0,all;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	scanf("%d",&all);
      	printf("%d\n",sum[x][all]);
      }
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int n,m,q,w[110],dp[4500][110][13],ss[4500];
inline int go(int msk,int sum,int wh){
	  if(sum<0)return 0;
	  if(dp[msk][sum][wh]!=-1)return dp[msk][sum][wh];
	  dp[msk][sum][wh]=ss[msk];
	  for(int i=wh;i<n;i++)
	    dp[msk][sum][wh]+=go(msk^(1<<i),sum-w[i],i+1);
	  return dp[msk][sum][wh];
}
int main(){
      int i,j,k;
      scanf("%d%d%d",&n,&m,&q);
      for(i=0;i<n;i++)scanf("%d",&w[i]);
      for(i=1;i<=m;i++){
      	int x=0;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	ss[x]++;
      }
      memset(dp,-1,sizeof(dp));
      for(i=0;i<(1<<n);i++)
        for(j=0;j<=100;j++)
          for(k=0;k<n;k++)
            go(i,j,k);
      for(i=1;i<=q;i++){
      	int x=0,sum;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	for(j=0;j<n;j++)x^=(1<<j);
      	scanf("%d",&sum);
      	printf("%d\n",dp[x][sum][0]);
      }
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int n,m,q,w[110],dp[4500][110],ss[4500];
inline int go(int msk,int sum,int wh){
	  if(sum<0)return 0;
	  if(dp[msk][sum]!=-1)return dp[msk][sum];
	  dp[msk][sum]=ss[msk];
	  for(int i=wh;i<n;i++)
	    dp[msk][sum]+=go(msk^(1<<i),sum-w[i],i+1);
	  return dp[msk][sum];
}
int main(){
      int i,j,k;
      scanf("%d%d%d",&n,&m,&q);
      for(i=0;i<n;i++)scanf("%d",&w[i]);
      for(i=1;i<=m;i++){
      	int x=0;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	ss[x]++;
      }
      for(i=1;i<=q;i++){
      	memset(dp,-1,sizeof(dp));
      	int x=0,sum;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	for(j=0;j<n;j++)x^=(1<<j);
      	scanf("%d",&sum);
      	printf("%d\n",go(x,sum,0));
      }
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define ri register int
int sum[4500][110],tot[4500],w[20],W[4500];
int main(){
      int n,m,q;
      scanf("%d%d%d",&n,&m,&q);
      for(ri i=0;i<n;++i)scanf("%d",&w[i]);
      for(ri i=1;i<=m;++i){
      	int x=0;
      	char s;
      	for(ri j=0;j<n;++j){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	tot[x]++;
      }
      for(ri i=0;i<(1<<n);++i)
        for(ri j=0;j<n;++j)
          if(!(i&(1<<j)))W[i]+=w[j];
      for(ri i=0;i<(1<<n);++i)
        for(ri j=0;j<(1<<n);++j)
          if(W[i^j]<=100)sum[i][W[i^j]]+=tot[j];
      for(ri i=0;i<(1<<n);++i)
        for(ri j=1;j<=100;++j)
          sum[i][j]+=sum[i][j-1];
      for(ri i=1;i<=q;++i){
      	int x=0,all;
      	char s;
      	for(ri j=0;j<n;++j){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	scanf("%d",&all);
      	printf("%d\n",sum[x][all]);
      }
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int n,m,q,w[110],dp[4500][110][13],ss[4500];
inline int go(int msk,int sum,int wh){
	  if(sum<0)return 0;
	  if(dp[msk][sum][wh]!=-1)return dp[msk][sum][wh];
	  dp[msk][sum][wh]=ss[msk];
	  for(int i=wh;i<n;i++)
	    dp[msk][sum][wh]+=go(msk^(1<<i),sum-w[i],i+1);
	  return dp[msk][sum][wh];
}
int main(){
      int i,j,k;
      scanf("%d%d%d",&n,&m,&q);
      for(i=0;i<n;i++)scanf("%d",&w[i]);
      for(i=1;i<=m;i++){
      	int x=0;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	ss[x]++;
      }
      memset(dp,-1,sizeof(dp));
      for(i=1;i<=q;i++){
      	int x=0,sum;
      	char s;
      	for(j=0;j<n;j++){
      	  cin>>s;
      	  if(s=='1')x|=(1<<j);
      	}
      	for(j=0;j<n;j++)x^=(1<<j);
      	scanf("%d",&sum);
      	printf("%d\n",go(x,sum,0));
      }
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define ri register int
int sum[4500][110],tot[4500],w[20],W[4500];
char s[20];
int main(){
      int n,m,q;
      scanf("%d%d%d",&n,&m,&q);
      for(ri i=0;i<n;++i)scanf("%d",&w[i]);
      for(ri i=1;i<=m;++i){
      	int x=0;
      	scanf("%s",s);
      	for(ri j=0;j<n;++j){
      	  if(s[j]=='1')x|=(1<<j);
      	}
      	tot[x]++;
      }
      for(ri i=0;i<(1<<n);++i)
        for(ri j=0;j<n;++j)
          if(!(i&(1<<j)))W[i]+=w[j];
      for(ri i=0;i<(1<<n);++i)
        for(ri j=0;j<(1<<n);++j)
          if(W[i^j]<=100)sum[i][W[i^j]]+=tot[j];
      for(ri i=0;i<(1<<n);++i)
        for(ri j=1;j<=100;++j)
          sum[i][j]+=sum[i][j-1];
      for(ri i=1;i<=q;++i){
      	int x=0,all;
      	scanf("%s %d",s,&all);
      	for(ri j=0;j<n;++j){
      	  if(s[j]=='1')x|=(1<<j);
      	}
      	printf("%d\n",sum[x][all]);
      }
	  return 0;
}


// dile a la jardinera que traigo flores
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fill(x,v) memset(x,v,sizeof(x))
#define FOR(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 15
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int w[N];
int cant[4100];

int main(){

	int n,m,q;
	scanf("%d %d %d\n",&n,&m,&q);
	FOR(i,0,n) scanf("%d",w+i);
	scanf("\n");
	char car;
	fill(cant,0);
	FOR(i,0,m){
		int num = 0;
		for(int i = 0; i < n; ++i){
			scanf("%c",&car);
			if(car == '1')
				num |= (1 << (n-i-1));
		}
		scanf("\n");
		cant[num]++;
	}

	int lim = (1 << n);
	int dp[4100][105];
	fill(dp,0);

	for(int i = 0; i < lim; ++i){
		for(int j = 0; j < lim; ++j){
			int score = 0;
			for(int k = 0; k < n; ++k)
				if( (i&(1<<k)) == (j&(1<<k)) )
					score += w[n-1-k];
			if(score <= 100)
				dp[i][score] += cant[j];
		}
	}

	int ans[5000][105];
	for(int i = 0; i < lim; ++i){
		ans[i][0] = dp[i][0];
		for(int j = 1; j <= 100; ++j)
			ans[i][j] = ans[i][j-1] + dp[i][j];
	}

	int k;
	FOR(i,0,q){
		int num = 0;
		for(int j = 0; j < n; ++j){
			scanf("%c",&car);
			if(car == '1') num |= (1<<(n-1-j));
		}
		scanf("%d\n",&k);
		printf("%d\n",ans[num][k]);
	}

	return 0;
}


// dile a la jardinera que traigo flores
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fill(x,v) memset(x,v,sizeof(x))
#define FOR(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 15
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int w[N];
int cant[5000];

int main(){

	fastio;
	int n,m,q;
	cin >> n >> m >> q;
	FOR(i,0,n) cin >> w[i];

	char car;
	fill(cant,0);
	FOR(i,0,m){
		int num = 0;
		for(int i = 0; i < n; ++i){
			cin >> car;
			if(car == '1')
				num |= (1 << (n-i-1));
		}
		cant[num]++;
	}

	string cad; int k;
	int lim = (1 << n);
	FOR(i,0,q){
		cin >> cad >> k;
		int ans = 0;
		for(int i = 0; i < lim; ++i){
			int score = 0;
			for(int j = 0; j < n; ++j){
				if( (cad[j]-'0') == ((i&(1<<(n-j-1))) > 0) )
					score += w[j];
			}
			if(score <= k) ans += cant[i];
		}
		cout << ans << endl;
	}

	return 0;
}


// dile a la jardinera que traigo flores
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fill(x,v) memset(x,v,sizeof(x))
#define FOR(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 15
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int w[N];
int cant[5000];

int main(){

	fastio;
	int n,m,q;
	cin >> n >> m >> q;
	FOR(i,0,n) cin >> w[i];

	char car;
	fill(cant,0);
	FOR(i,0,m){
		int num = 0;
		for(int i = 0; i < n; ++i){
			cin >> car;
			if(car == '1')
				num |= (1 << (n-i-1));
		}
		cant[num]++;
	}

	int lim = (1 << n);
	int dp[5000][105];
	fill(dp,0);

	for(int i = 0; i < lim; ++i){
		for(int j = 0; j < lim; ++j){
			int score = 0;
			for(int k = 0; k < n; ++k)
				if( (i&(1<<k)) == (j&(1<<k)) )
					score += w[n-1-k];
			if(score <= 100)
				dp[i][score] += cant[j];
		}
	}

	int ans[5000][105];
	for(int i = 0; i < lim; ++i){
		ans[i][0] = dp[i][0];
		for(int j = 1; j <= 100; ++j)
			ans[i][j] = ans[i][j-1] + dp[i][j];
	}

	int k;
	FOR(i,0,q){
		int num = 0;
		for(int j = 0; j < n; ++j){
			cin >> car;
			if(car == '1') num |= (1<<(n-1-j));
		}
		cin >> k;
		cout << ans[num][k] << endl;
	}

	return 0;
}


// dile a la jardinera que traigo flores
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fill(x,v) memset(x,v,sizeof(x))
#define FOR(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 15
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int w[N];
int cant[5000];

int main(){

	int n,m,q;
	scanf("%d %d %d\n",&n,&m,&q);
	FOR(i,0,n) scanf("%d",w+i);
	scanf("\n");
	char car;
	fill(cant,0);
	FOR(i,0,m){
		int num = 0;
		for(int i = 0; i < n; ++i){
			scanf("%c",&car);
			if(car == '1')
				num |= (1 << (n-i-1));
		}
		scanf("\n");
		cant[num]++;
	}

	int lim = (1 << n);
	int dp[5000][105];
	fill(dp,0);

	for(int i = 0; i < lim; ++i){
		for(int j = 0; j < lim; ++j){
			int score = 0;
			for(int k = 0; k < n; ++k)
				if( (i&(1<<k)) == (j&(1<<k)) )
					score += w[n-1-k];
			if(score <= 100)
				dp[i][score] += cant[j];
		}
	}

	int ans[5000][105];
	for(int i = 0; i < lim; ++i){
		ans[i][0] = dp[i][0];
		for(int j = 1; j <= 100; ++j)
			ans[i][j] = ans[i][j-1] + dp[i][j];
	}

	int k;
	FOR(i,0,q){
		int num = 0;
		for(int j = 0; j < n; ++j){
			scanf("%c",&car);
			if(car == '1') num |= (1<<(n-1-j));
		}
		scanf("%d\n",&k);
		cout << ans[num][k] << endl;
	}

	return 0;
}


// dile a la jardinera que traigo flores
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fill(x,v) memset(x,v,sizeof(x))
#define FOR(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 15
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int w[N];
int cant[5000];

int main(){

	fastio;
	int n,m,q;
	cin >> n >> m >> q;
	FOR(i,0,n) cin >> w[i];

	char car;
	fill(cant,0);
	FOR(i,0,m){
		int num = 0;
		for(int i = 0; i < n; ++i){
			cin >> car;
			if(car == '1')
				num |= (1 << (n-i-1));
		}
		cant[num]++;
	}

	int k;
	int lim = (1 << n);
	FOR(i,0,q){
		int ans = 0;
		for(int i = 0; i < lim; ++i){
			int score = 0;
			for(int j = 0; j < n; ++j){
				cin >> car;
				if( (car-'0') == ((i&(1<<(n-j-1))) > 0) )
					score += w[j];
			}
			if(score <= k) ans += cant[i];
		}
		cout << ans << endl;
	}

	return 0;
}


// dile a la jardinera que traigo flores
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fill(x,v) memset(x,v,sizeof(x))
#define FOR(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 15
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int w[N];
int cant[5000];

int main(){

	int n,m,q;
	cin >> n >> m >> q;
	FOR(i,0,n) cin >> w[i];

	char car;
	fill(cant,0);
	FOR(i,0,m){
		int num = 0;
		for(int i = 0; i < n; ++i){
			cin >> car;
			if(car == '1')
				num |= (1 << (n-i-1));
		}
		cant[num]++;
	}

	int k; string cad;
	int lim = (1 << n);
	int dp[5000][105];
	fill(dp,-1);
	FOR(i,0,q){
		cin >> cad >> k;
		int num = 0;
		for(int i = 0; i < n; ++i)
			if(cad[i] == '1') num |= (1 << (n-i-1));

		if(dp[num][k] != -1){
			cout << dp[num][k] << endl;
			continue;
		}
		int ans = 0;
		for(int i = 0; i < lim; ++i){
			int score = 0;
			for(int j = 0; j < n; ++j){
				if( (num & (1<<(n-j-1))) == (i&(1<<(n-j-1))) )
					score += w[j];
			}
			if(score <= k) ans += cant[i];
		}
		dp[num][k] = ans;
		cout << ans << endl;
	}

	return 0;
}


// dile a la jardinera que traigo flores
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fill(x,v) memset(x,v,sizeof(x))
#define FOR(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 15
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int w[N];
int cant[5000];

int main(){

	int n,m,q;
	cin >> n >> m >> q;
	FOR(i,0,n) cin >> w[i];

	char car;
	fill(cant,0);
	FOR(i,0,m){
		int num = 0;
		for(int i = 0; i < n; ++i){
			cin >> car;
			if(car == '1')
				num |= (1 << (n-i-1));
		}
		cant[num]++;
	}

	int lim = (1 << n);
	int dp[5000][105];
	fill(dp,0);

	for(int i = 0; i < lim; ++i){
		for(int j = 0; j < lim; ++j){
			int score = 0;
			for(int k = 0; k < n; ++k)
				if( (i&(1<<k)) == (j&(1<<k)) )
					score += w[n-1-k];
			if(score <= 100)
				dp[i][score] += cant[j];
		}
	}

	int ans[5000][105];
	for(int i = 0; i < lim; ++i){
		ans[i][0] = dp[i][0];
		for(int j = 1; j <= 100; ++j)
			ans[i][j] = ans[i][j-1] + dp[i][j];
	}

	int k;
	FOR(i,0,q){
		int num = 0;
		for(int j = 0; j < n; ++j){
			cin >> car;
			if(car == '1') num |= (1<<(n-1-j));
		}
		cin >> k;
		cout << ans[num][k] << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

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

ll nMod = 1e9 + 7;

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

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

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

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

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

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

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

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

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

ll nMod = 1e9 + 7;

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

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

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

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

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

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

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

ll nMod = 1e9 + 7;

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

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

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

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

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

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

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

    return 0;
}