C++// A
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
if(n==2)cout<<2<<endl;
else if(n==3)cout<<3<<endl;
else
{
if(n%2==1)cout<<1<<endl;
else cout<<0<<endl;
}
}
return 0;
}
//B
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
int T;
cin>>T;
while(T--)
{
int s,m,k;
cin>>s>>m>>k;
int times=k%(2*m);
if(times>=m)
{
times-=m;
s=min(s,m);
}
if(times==0)
cout<<s<<endl;
else if(times<=s)
cout<<s-times<<endl;
else cout<<0<<endl;
}
return 0;
}