#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<cstdio>
#define R(i,a,n) for(register int i=(a);i<=(n);i++)
#define F(i,a,n) for(register int i=(n);i>=(a);i--)
using namespace std;
typedef long long ll;
template<class T> void read(T &x) {
x = 0; int f = 0; char ch = getchar();
while (ch < '0' || ch > '9') {f |= (ch == '-'); ch = getchar();}
while (ch >= '0' && ch <= '9') {x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();}
x = f ? -x : x;
return;
}
ll a[20];
ll l,r;
int T;
int main()
{
read(l);read(r);read(T);
while(T--)
{
string s;
cin>>s;
int len=s.size();
if(s[0]=='-')
{
if(len==1)
{
printf("%d\n",1);
continue;
}
if(s[1]=='0')
{
printf("%d\n",1);
continue;
}
if(len<=20)
{
ll ans=0;
for(int i=1;i<len;i++)
{
ans=ans*10+(ll)(s[i]-'0');
}
ans*=-1;
/*if(ans<-9223372036854775808)
{
printf("%d\n",0);
continue;
}*/
if(ans>=l&&ans<=r) printf("%d\n",0);//
else printf("%d\n",2);
}
else
printf("%d\n",2);
continue;
}
if(s[0]=='0'&&len>=2)
{
printf("%d\n",1);
continue;
}
if(len<=19)
{
ll ans=0;
for(int i=0;i<len;i++)
{
ans=ans*10+(ll)(s[i]-'0');
}
if(ans>=l&&ans<=r) printf("%d\n",0);//x+10000
else
{
printf("%d\n",2);
}
}
else
{
printf("%d\n",2);
}
}
return 0;
}