#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
    ll l,r;
    int m;
    cin>>l>>r;
    cin>>m;
    ll sum = (l+r)*(r-l+1)/2;
    while(m--)
    {
        ll x;
        cin>>x;
        if(sum%x)cout<<1<<'\n';
        else cout<<0<<'\n';
    }

}

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

guess了一波,猜对了