#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define int         ll int
#define	endl		'\n'
#define mii         map<int,int>
#define msi         map<string,int>
#define mis         map< int, string>
#define mpi         map<pair< int, int>, int>
#define pii         pair< int, int>
#define vi          vector< int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;

#define N  100005
int min(int a,int b)
{
	if(a>=b)
	{
		return b;
	}
	else
	{
		return a;
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
	    int n,d;
	    cin>>n>>d;
	    int i,j,k;
	    int a=sqrt(d);
	    int ans=INT_MAX;
	    if(d<=n)
	    {
	    	cout<<"YES"<<endl;
	    	continue;
		}
	    for(i=0;i<=a+1;i++)
	    {
	    	ans=min(ans,i+(int)ceil((double)d/(i+1)));//Kyu float aur double me phas jate ho
		}
		if(ans<=n)
		{
			cout<<"YES"<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
    }
}


#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define int         ll int
#define	endl		'\n'
#define mii         map<int,int>
#define msi         map<string,int>
#define mis         map< int, string>
#define mpi         map<pair< int, int>, int>
#define pii         pair< int, int>
#define vi          vector< int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;

#define N  100005

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    	int n,d;
    	cin>>n>>d;
    	if(d<=n)
    	{
    		cout<<"YES"<<endl;
    		continue;
		}
		else
		{
			int c=0;
			for(int i=1;i<=d;i++)
			{
				if(i+ceil((float)d/(i+1))<=n)
				{
					cout<<"YES"<<endl;
					c=1;
					break;
				}
			}
			if(!c)
			{
				cout<<"NO"<<endl;
			}

		}
	}
}


#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define int         ll int
#define	endl		'\n'
#define mii         map<int,int>
#define msi         map<string,int>
#define mis         map< int, string>
#define mpi         map<pair< int, int>, int>
#define pii         pair< int, int>
#define vi          vector< int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;

#define N  100005

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    	int n,d;
    	int i,j,k;
    	cin>>n>>d;
    	if(d<=n)
    	{
    		cout<<"YES"<<endl;
    		continue;
		}
		else
		{
			int c=0;
			for(i=1;i<=d;i++)
			{
				if(i==ceil((float)d/(i+1)))
				{
					break;
				}
			}
			if(2*i<=n)
			{
				cout<<"YES"<<endl;
			}
			else
			{
				cout<<"NO"<<endl;
			}

		}
	}
}


#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define int         ll int
#define	endl		'\n'
#define mii         map<int,int>
#define msi         map<string,int>
#define mis         map< int, string>
#define mpi         map<pair< int, int>, int>
#define pii         pair< int, int>
#define vi          vector< int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;

#define N  100005

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
    	int n,d;
    	int i,j,k;
    	cin>>n>>d;
    	if(d<=n)
    	{
    		cout<<"YES"<<endl;
    		continue;
		}
		else
		{
			int c=0;
			for(i=0;i<=d;i++)
			{
				//cout<<i<<" "<<ceil((float)d/(i+1))<<endl;
				if(i>=ceil((float)d/(i+1)))
				{
					break;
				}
			}
			if(i+ceil((float)d/(i+1))<=n)
			{
				cout<<"YES"<<endl;
			}
			else
			{
				cout<<"NO"<<endl;
			}

		}
	}
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
	int q;
	cin>>q;
	while(q--){
		double n,d;
		bool cond = 0;
		cin>>n>>d;
		cond = n/2+(d/(ceil(n/2)+1)) <= n;
		if(cond)cout << "yes"<<endl;
		else cout << "no"<<endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int q;
	cin>>q;
	while(q--){
		double n,d;
		bool cond = 0;
		cin>>n>>d;
		if(d <= n){cout << "yes\n";continue;}
		if((n-1)+floor(d/n) <= n)cond = 1;
		if(cond)cout << "yes"<<endl;
		else cout << "no"<<endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int q;
	cin>>q;
	while(q--){
		double n,d;
		bool cond = 0;
		cin>>n>>d;
		for(int i=0;i<n;i++){
			if(i+(d/(i+1))<=n){cond=1;break;}
		}
		if(cond)cout << "yes"<<endl;
		else cout << "no"<<endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
	int q;
	cin>>q;
	while(q--){
		int n,d;
		cin>>n>>d;
		if(floor(d/n)<=1){
			cout << "Yes\n";
		}else cout<<"No\n";
	}
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
	int q;
	cin>>q;
	while(q--){
		int n,d;
		bool cond = 0;
		cin>>n>>d;
		//if(d <= n || ((d-n == 1)&&n>2))cond = 1;
		if(d < n*2)cond = 1;
		if(cond)cout << "yes"<<endl;
		else cout << "no"<<endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int q;
	cin>>q;
	while(q--){
		double n,d;
		bool cond = 0;
		cin>>n>>d;
		if(d <= n){cout << "yes\n";continue;}
		if((n/2)+ceil(d/((n/2)+1)) <= n)cond = 1;
		if(cond)cout << "yes"<<endl;
		else cout << "no"<<endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
	int q;
	cin>>q;
	while(q--){
		int n,d;
		bool cond = 0;
		cin>>n>>d;
		if(d <= n){cout << "yes\n";continue;}
		if(1+ceil((double)d/2)<= n)cond = 1;
		if(cond)cout << "yes"<<endl;
		else cout << "no"<<endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
	int q;
	cin>>q;
	while(q--){
		int n,d;
		cin>>n>>d;
		if(d <= n){
			cout <<"yes"<<endl;continue;
		}
		bool cond = (floor(d/2)+(n/(floor(d/2)+1)))<=n;
		if(cond)cout << "yes"<<endl;
		else cout << "no"<<endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
	int q;
	cin>>q;
	while(q--){
		double n,d;
		bool cond = 0;
		cin>>n>>d;
		if(d <= n || ((d-n == 1)&&n>2))cond = 1;
		if(cond)cout << "yes"<<endl;
		else cout << "no"<<endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
	int q;
	cin>>q;
	while(q--){
		int n,d;
		bool cond = 0;
		cin>>n>>d;
		if(d <= n || (d-n == 1 && n != 1)){
			cond = 1;
		}else{
			cond = 0;
		}
		if(cond)cout << "yes"<<endl;
		else cout << "no"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,d,f=0;
        cin>>n>>d;
        if(d<=n)
        {
            cout<<"YES"<<endl;
        }
        else
        {
        for(int i=1;i*i<=n;i++)
        {
            if(ceil(d/(i+1))+i<n)
            {
                f=1;
                break;
            }
        }
        if(f==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        }
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,d,f=0;
        cin>>n>>d;
        if(d<=n)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            for(int i=1;i<=n;i++)
            {
                if(ceil(d/(i+1))+i<n)
                {
                    f=1;
                    break;
                }
            }
            if(f==1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,d,f=0;
        cin>>n>>d;
        if(d<=n)
        {
            cout<<"YES"<<endl;
        }
        else
        {
        for(int i=1;i*i<n;i++)
        {
            if(ceil(d/(i+1))+i<n)
            {
                f=1;
                break;
            }
        }
        if(f==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        }
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        float n,d,f=0;
        cin>>n>>d;
        if(d<=n)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            for(int i=1;i*i<=n;i++)
            {
                if(ceil(d/(i+1))+i<=n)
                {
                    f=1;
                    break;
                }
            }
            if(f==1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,d,f=0;
        cin>>n>>d;
        if(d<=n)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            for(int i=1;i*i<n;i++)
            {
                if(ceil(d/(i+1))+i<=n)
                {
                    f=1;
                    break;
                }
            }
            if(f==1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,d,f=0;
        cin>>n>>d;
        if(d<=n)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            for(int i=1;i<n;i++)
            {
                if(ceil(d/(i+1))+i<n)
                {
                    f=1;
                    break;
                }
            }
            if(f==1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        float n,d,f=0;
        cin>>n>>d;
        if(d<=n)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            for(int i=1;i*i<n;i++)
            {
                if(ceil(d/(i+1))+i<=n)
                {
                    f=1;
                    break;
                }
            }
            if(f==1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        float n,d,f=0;
        cin>>n>>d;
        if(d<=n)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            for(int i=1;i<=n;i++)
            {
                if((float)ceil(d/(i+1))+i<=(float)n)
                {
                    f=1;
                    break;
                }
            }
            if(f==1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        float n,d,f=0;
        cin>>n>>d;
        if(d<=n)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            for(int i=1;i*i<=n;i++)
            {
                if((float)ceil(d/(i+1))+i<=(float)n)
                {
                    f=1;
                    break;
                }
            }
            if(f==1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
}
}


#include <iostream>
using namespace std;

int main() {

	int q; cin >> q;
	long long n;

	while (q--)
	{
		cin >> n;
		if (n==2)cout<<n<<'\n';
		else if (n%2==0)cout<<0<<'\n';
		else cout <<1<<'\n';
	}

	return 0;
}


#include <iostream>
using namespace std;

int main() {

	int q; cin >> q;
	long long n, i=1;
	long long y;
	while (q--){
		cin >> n;
		y=n/2;
		for (i=1; ;++i)
			if ((y+i)*2>n){break;}

	(n%8==0)?cout<<0<<'\n':cout << abs(n-(y+i)*2)<<'\n';
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {

	int q; cin >> q;
	int n, i=1;
	int y = n/2;
	while (q--){
		cin >> n;
		for (i=1; ;++i)
			if ((y+i)*2>n){break;}

	(n%8==0)?cout<<0<<'\n':cout << abs(n-(y+i)*2)<<'\n';
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
       int t;
       int n,k;
       cin >> t;
       while(t--)
       {
             cin >> n;
             if(n == 1)
             {
                    cout << 3 << endl;
                    continue;
             }
             if(n == 2)
             {
                    cout << 2 << endl;
                    continue;
             }
             if(n%2 == 0)
             {
                    cout << 0 << endl;
             }
             if(n%2 != 0) cout << 1 << endl;
       }
       return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
       int t;
       int n,k;
       cin >> t;
       while(t--)
       {
             cin >> n;
             if(n == 1)
             {
                    cout << 3 << endl;
                    continue;
             }
             if(n == 2)
             {
                    cout << 2 << endl;
                    continue;
             }
             if(n%2 == 0)
             {
                    cout >> 0 << endl;
             }
             if(n%2 != 0) cout << 1 << endl;
       }
       return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define F first
#define S second
#define sqr(x) ((x) * (x))
#define cub(x) ((x) * (x) * (x))
#define pii pair<int, int>
#define all(c) c.begin(), c.end()
#define tr(c, it) for(decltype (c.begin()) it = c.begin(); it != c.end(); it++)
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define for1(i, n) for(int i = 1; i <= int(n); i++)
#define forN(i, x, n) for(int i = x; i < int(n); i++)
#define eps 1e-12
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define inf 2e9
#define sz 2100
#define M 1000000007

#define name "input"
#define isFile 0

typedef unsigned long long ll;
typedef long double ld;

void faster(){
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    if(isFile){
        freopen(name".in", "r", stdin);
        freopen(name".out", "w", stdout);
    }
}
int n;
void solve(){
        cin >> n;

        if (n == 2 || n == 4)
            cout << "2\n";
        else if (n % 2)
            cout << "1\n";
        else
            cout << "0\n";
}
int main()
{
    faster();
    int t;
    cin>>t;
    while(t--)
	    solve();
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define F first
#define S second
#define sqr(x) ((x) * (x))
#define cub(x) ((x) * (x) * (x))
#define pii pair<int, int>
#define all(c) c.begin(), c.end()
#define tr(c, it) for(decltype (c.begin()) it = c.begin(); it != c.end(); it++)
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define for1(i, n) for(int i = 1; i <= int(n); i++)
#define forN(i, x, n) for(int i = x; i < int(n); i++)
#define eps 1e-12
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define inf 2e9
#define sz 2100
#define M 1000000007

#define name "input"
#define isFile 0

typedef unsigned long long ll;
typedef long double ld;

void faster(){
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    if(isFile){
        freopen(name".in", "r", stdin);
        freopen(name".out", "w", stdout);
    }
}
int n;
void solve(){
        cin >> n;

        if (n == 2)
            cout << "2\n";
        else if (n % 2)
            cout << "1\n";
        else
            cout << "0\n";
}
int main()
{
    faster();
    int t;
    cin>>t;
    while(t--)
	    solve();
    return 0;
}


#include <iostream>
using namespace std;
int main(){
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		if(n%2==0){
			cout<<0<<endl;
			continue;
		}
		int x=1,y=1;
		int temp;
		while(1){
			temp=2*(x+y);
			if(temp>=n){
				break;
			}
			x++;
			temp=2*(x+y);
			if(temp>=n){
				break;
			}
			y++;
		}
		cout<<2*(x+y)-n<<endl;
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main(){
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		int x=1,y=1;
		int temp;
		while(1){
			temp=2*(x+y);
			if(temp>=n){
				break;
			}
			x++;
			temp=2*(x+y);
			if(temp>=n){
				break;
			}
			y++;
		}
		cout<<2*(x+y)-n<<endl;
	}

	return 0;
}


#include <iostream>
using namespace std;
int main(){
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		if(n==2){
			cout<<2<<endl;
			continue;
		}
		if(n%2==0){
			cout<<0<<endl;
			continue;
		}
		cout<<1<<endl;
	}

	return 0;
}


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

int main() {
    int t;  cin>>t;
    while (t--) {
        int x;  cin>>x;
        if (x<4) cout<<4-x;
        else cout<<(x%1);
    }
    return 0;
}


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

int main() {
    int t;  cin>>t;
    while (t--) {
        int x;  cin>>x;
        if (x<4) cout<<4-x;
        else cout<<x&1;
    }
    return 0;
}


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

int main() {
    int t;  cin>>t;
    while (t--) {
        int x;  cin>>x;
        if (x<4) cout<<4-x;
        else cout<<x%2;
    }
    return 0;
}


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

#define else if elif

int main() {
    int t;  cin>>t;
    while (t--) {
        int x;  cin>>x;
        if (x<4) cout<<4-x;
        else cout<<x&1;
    }
    return 0;
}


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

int main() {
    int t;  cin>>t;
    while (t--) {
        int x;  cin>>x;
        if (x<4) cout<<4-x;
        else cout<<x%2;

        cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define endl "\n"
#define vci vector<int>
#define vcl vector<long long>
#define mpi map<int,int>
#define mpl map<long long,long long>
#define vecp vector<pair<<int,int> >
int main()
{
	ll n,t,i,j,b,k,mini,l1,l2,r1,r2,c,d,maxi,x,y,a,g;
	cin >> t;
	while(t--)
	{
		cin > n;
		if(n==2)
		{
		    cout << 2 << endl;
		}
		else if(n==3)
		{
		    cout << 1 << endl;
		}
		else
		{
		    if(n%2==0)
		    {
		        cout << 0 << endl;
		    }
		    else
		    {
		        cout << 1 << endl;
		    }
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define endl "\n"
#define vci vector<int>
#define vcl vector<long long>
#define mpi map<int,int>
#define mpl map<long long,long long>
#define vecp vector<pair<<int,int> >
int main()
{
	ll n,t,i,j,b,k,mini,l1,l2,r1,r2,c,d,maxi,x,y,a,g;
	cin >> t;
	while(t--)
	{
		cin >> n;
		if(n==2)
		{
		    cout << 2 << endl;
		}
		else if(n==3)
		{
		    cout << 1 << endl;
		}
		else
		{
		    if(n%2==0)
		    {
		        cout << 0 << endl;
		    }
		    else
		    {
		        cout << 1 << endl;
		    }
		}
	}
}


#include <bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb(a)   push_back(a)
#define debug(a) cerr<<#a<<"  --  "<<a<<endl;
using namespace std;
#define ll long long int
int main() {
     ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n,t,a,b,x;
    cin>>t;
    while(t--){
        cin>>n;
        x=n/2 + (n%2 !=0);
        if(x%2!=0){
            a=x/2;b=x/2 + (x%2 !=0);
            if(a==0)    a=1;
            if(b==0)    b=1;
            x=a+b;
        }
        else{
            a=x/2;b=a;
            if(a==0)    a=1;
            if(b==0)    b=1;
            x=a+b;
        }
        // cout<<a<<" "<<b<<" "<<x<<" "<<n<<endl;
        cout<<((a+b+x)-n)<<endl;
    }
}


#include <bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb(a)   push_back(a)
#define debug(a) cerr<<#a<<"  --  "<<a<<endl;
using namespace std;
#define ll long long int
int main() {
     ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n,t;
    cin>>t;
    while(t--){
        cin>>n;
        if(n==2)    cout<<2;
        else if(n%2==0) cout<<0;
        else    cout<<1;
        cout<<endl;
    }
}


//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
int main(){
	int q, n[1000];
	cin >> q;
	for(int i = 0; i < q; i++){
		cin >> n[i];
	}
	for(int i = 0; i < q; i++){
		if(n[i] == 2)
			cout << 2 << endl;
		else
			cout << n[i] % 2 << endl;
	}
	return 0;
}


//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
int main(){
	int q, n[1000];
	cin >> q;
	for(int i = 0; i < q; i++){
		cin >> n;
		if(n == 2)
			cout << 2;
		else
			cout << n % 2;
	}
	return 0;
}


//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
int main(){
	int q, n;
	cin >> q;
	for(int i = 0; i < q; i++){
		cin >> n;
		if(n == 2)
			cout << 2;
		else
			cout << n % 2;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{

	    int n;
	    cin>>n;
	    if(4-(n%4)!=4)
	    cout<<4-(n%4)<<endl;
	    else
	    cout<<0<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{

	    int n;
	    cin>>n;
	    if(n==1)
	    cout<<3<<endl;
	    else if(n==2)
	    cout<<2<<endl;
	    else if(n==3)
	    cout<<1<<endl;
	   // if(4-(n%4)!=4)
	   // cout<<4-(n%4)<<endl;
	   // else
	   // cout<<0<<endl;
	   else
	   cout<<n%2<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{

	    int n;
	    cin>>n;
	    cout<<4-(n%4)<<endl;
	}

	return 0;
}


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

int main(){

  int q;
  cin >>q;
  while( q-- ){

     ll n;
     cin >>n;

     double frac = n/(2*1.0);
     ll c = ceil(frac);

     ll left = n - c;

     if( left < c ){
         cout<<c-left<<endl;
     }
     else{
        if( left == 1 ){
            cout<<2<<endl;
        }
        else
          cout<<0<<endl;
     }
  }
  return 0;
}


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

int main(){

  int q;
  cin >>q;
  while( q-- ){

     ll n;
     cin >>n;

     double frac = n/(2*1.0);
     ll c = ceil(frac);

     ll left = n - c;

     if( left < c ){
         cout<<c-left<<endl;
     }
     else{

        if( left % 2 == 0 ) // even
        {
            cout<<0<<endl;
        }
        else{
            cout<<2<<endl;
        }
     }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(int i=k;i<n;i++)
#define all(x) x.begin(),x.end()
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define xx first
#define yy second
#define MOD 1000000007
#define pb push_back
typedef long long ll;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}

int main(){
	FAST
	int q,n;
	cin >> q;
	rep(i,q){
		cin >> n;
		int d = n % 4;
		if(d == 0){
			cout << 0;
		}
		else if(d == 1){
			cout << 1;
		}
		else if(d == 2){
			cout << 2;
		}
		else{
			cout << 1;
		}
		cout << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(int i=k;i<n;i++)
#define all(x) x.begin(),x.end()
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define xx first
#define yy second
#define MOD 1000000007
#define pb push_back
typedef long long ll;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}

int main(){
	FAST
	int q,n;
	cin >> q;
	rep(i,q){
		cin >> n;
		int d = n % 4;
		if(n == 0){
			cout << 0;
		}
		else if(n == 1){
			cout << 1;
		}
		else if(n == 2){
			cout << 2;
		}
		else{
			cout << 1;
		}
		cout << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(int i=k;i<n;i++)
#define all(x) x.begin(),x.end()
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define xx first
#define yy second
#define MOD 1000000007
#define pb push_back
typedef long long ll;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}

int main(){
	FAST
	int q,n;
	cin >> q;
	rep(i,q){
		cin >> n;
		int d = n % 4;
		if(n <= 4){
			cout <<  4-n;
		}
		else{
			cout << (d & 1);
		}
		cout << '\n';
	}

	return 0;
}


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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define pi acos(-1.0)
#define eps 1e-8
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    int q, n ;
    cin>> q ;
    while(q--)
      {
        cin>> n ;
        if(n==2) cout<< 2 ;
        else if(n%2) cout<< 1 ;
        else cout<< 0 ;
      }
  }


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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define pi acos(-1.0)
#define eps 1e-8
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    int n, ans=0 ;
    cin>> n ;
    if(n==2) cout<< 2 ;
    else if(n%2) cout<< 1 ;
    else cout<< 0 ;
  }


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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define pi acos(-1.0)
#define eps 1e-8
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    int q, n ;
    cin>> q ;
    while(q--)
      {
        cin>> n ;
        if(n==2) cout<< 2 << endl ;
        else if(n%2) cout<< 1 << endl ;
        else cout<< 0 << endl ;
      }
  }


/*
                                                          GHOSTRIDER
*/

#include<bits/stdc++.h>
#define Fast  std::ios::sync_with_stdio(false);  cin.tie(NULL);
#define pb  push_back
#define mp  make_pair
#define fi  first
#define se  second
#define all(x) x.begin(),x.end()
#define p pair<ll,ll>
#define in insert
#define endl '\n'
#define PI  (double)(3.14159265358979323846264338327950)
using namespace std;
typedef long long ll;

 const ll mod = 1e9+7;

 ll i,j;

  int main()
{

    Fast;

     ll t;
      cin>>t;

        while(t--)
        {
          ll n;
           cin>>n;

           if(n==1)
               {
                   cout<<3<<endl;
                    continue;
               }

             n=n%4;

                if(n==1 || n==3)
               cout<<1<<endl;

               else if(n==2)
                 cout<<2<<endl;

                 else
                   cout<<0<<endl;

        }
}


/*
                                                          GHOSTRIDER
*/

#include<bits/stdc++.h>
#define Fast  std::ios::sync_with_stdio(false);  cin.tie(NULL);
#define pb  push_back
#define mp  make_pair
#define fi  first
#define se  second
#define all(x) x.begin(),x.end()
#define p pair<ll,ll>
#define in insert
#define endl '\n'
#define PI  (double)(3.14159265358979323846264338327950)
using namespace std;
typedef long long ll;

 const ll mod = 1e9+7;

 ll i,j;

  int main()
{

    Fast;

     ll t;
      cin>>t;

        while(t--)
        {
          ll n;
           cin>>n;

           if(n==1)
               {
                   cout<<3<<endl;
                    continue;
               }

              if(n==2)
               {
                   cout<<2<<endl;
                    continue;
               }

                if(n==3)
               {
                   cout<<1<<endl;
                    continue;
               }

                if(n==4)
               {
                   cout<<0<<endl;
                    continue;
               }

             n=n-4;

                  if(n%2)
                    cout<<1<<endl;

                    else
                     cout<<0<<endl;
        }
}


/*
                                                          GHOSTRIDER
*/

#include<bits/stdc++.h>
#define Fast  std::ios::sync_with_stdio(false);  cin.tie(NULL);
#define pb  push_back
#define mp  make_pair
#define fi  first
#define se  second
#define all(x) x.begin(),x.end()
#define p pair<ll,ll>
#define in insert
#define endl '\n'
#define PI  (double)(3.14159265358979323846264338327950)
using namespace std;
typedef long long ll;

 const ll mod = 1e9+7;

 ll i,j;

  int main()
{

    Fast;

    ll t;
     cin>>t;

       while(t--)
       {
           ll n;
             cin>>n;

              n=n%4;

               if(n==1)
                 cout<<1<<endl;

                 else if(n==2)
                 {
                     cout<<2<<endl;
                 }

                 else if(n==3)
                  cout<<1<<endl;

                  else
                    cout<<0<<endl;

       }
}


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

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

    while(q--) {
        string s,t;
        cin>>s>>t;

        vector<bool> charofs(26,false);
        for(auto x : s)
            charofs[x-'a'] = true;

        int i;
        for(i=0; i<t.size(); i++) {
            if(charofs[t[i]-'a']) {
                cout<<"YES"<<endl;
                break;
            }
        }
        if(i == t.size())
            cout<<"NO"<<endl;
    }

    return 0;
}


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

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

    while(q--) {
        int n;
        cin>>n;

        if(n < 4) {
            cout<<(4-n)<<endl;
            continue;
        }

        if(n%2)
            cout<<1<<endl;
        else
            cout<<0<<endl;
    }

    return 0;
}


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

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

    while(q--) {
        string s,t;
        cin>>s>>t;

        vector<bool> chars(26,false);
        for(auto x : s)
            chars[x-'a'] = true;

        int i;
        for(i=0; i<t.size(); i++) {
            if(chars[t[i]-'a']) {
                cout<<"YES"<<endl;
                break;
            }
        }
        if(i == t.size())
            cout<<"NO"<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n%2==0){
        int x=n/2;
        if(x%2==0){
            cout<<"0"<<endl;
        }
        else {
            while(x%2!=0){
                x++;
            }
            cout<<x<<endl;
        }
        }
        else{

            int x=n+1;
            while(x%2!=0&&(x/2)%2!=0){
                     x++;
            }
          int count=x-n;
          int y=n-1;
          while(y%2!=0&&(y/2)%2!=0){
              y--;
          }
          int count1=n-y;
          cout<<min(count,count1)<<endl;
        }
    }

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{

    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n%2==0){
        int x=n/2;
        if(x%2==0){
            cout<<"0"<<endl;
        }
        else {
            while(x%2!=0){
                x++;
            }
            cout<<2*x-(n)<<endl;
        }
        }
        else{

            int x=n+1;
            while(x%2!=0&&(x/2)%2!=0){
                     x++;
            }
          int count=x-n;
          int y=n-1;
          while(y%2!=0&&(y/2)%2!=0){
              y--;
          }
          int count1=n-y;
          cout<<min(count,count1)<<endl;
        }
    }

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{

    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n%2==0){
        int x=n/2;
        if(x%2==0){
            cout<<"0"<<endl;
        }
        else {
            while(x%2!=0){
                x++;
            }
            cout<<x<<endl;
        }
        }
        else{
            int x=n+1;
            while(x%2!=0&&(x/2)%2!=0){
                     x++;
            }
            cout<<x-n<<endl;
        }
    }

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{

    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n%2==0){
        int x=n/2;
        if(x%2==0){
            cout<<"0"<<endl;
        }
        else {
            while(x%2!=0){
                x++;
            }
            cout<<x-(n/2)<<endl;
        }
        }
        else{

            int x=n+1;
            while(x%2!=0&&(x/2)%2!=0){
                     x++;
            }
          int count=x-n;
          int y=n-1;
          while(y%2!=0&&(y/2)%2!=0){
              y--;
          }
          int count1=n-y;
          cout<<min(count,count1)<<endl;
        }
    }

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{

    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n == 2)
			cout << 2;
		else if(n % 2 == 0)
			cout << 0;
		else cout << 1;
		cout << '\n';
    }
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;cin >> n;
	while(n--){
		unsigned int x;cin >> x;
		cout << (n == 2 ? n : n % 2);
	}
}


/*
    koroche
*/

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
    	int n;cin >> n;
    	while(n--){
    		unsigned int x;cin >> x;
    		cout << (x == 2 ? x : x % 2) << '\n';
    	}
    }


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;cin >> n;
	while(n--){
		unsigned int x;cin >> x;
		cout << (n == 2 ? n : n % 2) << '\n';
	}
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define um unordered_map
#define all(x) (x).begin(),(x).end()
#define forn(i,n) for(int i=0;i<int(n);++i)
#define for1(i,n) for(int i=1;i<=int(n);++i)
#define ford(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define fore(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define che(x) cout<<#x<<" having "<<x<<endl
using namespace std;
typedef long double ld;typedef long long ll;
typedef vector<int> vi;typedef vector<pair<int,int>> vpi;typedef vector<vi> vvi;
typedef vector<ll> vll;typedef vector<pair<ll,ll>> vpll;typedef vector<vll> vvll;
template<class T>bool uin(T &a,T b){return a>b?(a=b,true):false;}
template<class T>bool uax(T &a,T b){return a<b?(a=b,true):false;}
const ll MOD=1e9+7,INF=1e18;
/********************************************************************************/

int32_t main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);
    cout.precision(10);cout<<fixed;
#ifndef ONLINE_JUDGE
    freopen("input.txt","rt",stdin);
#endif

    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n==2||n==3) cout<<"2"<<endl;
        else if(n%2==0) cout<<"0"<<endl;
        else cout<<"1"<<endl;
    }

#ifndef ONLINE_JUDGE
    cerr<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
#endif
    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define um unordered_map
#define all(x) (x).begin(),(x).end()
#define forn(i,n) for(int i=0;i<int(n);++i)
#define for1(i,n) for(int i=1;i<=int(n);++i)
#define ford(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define fore(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define che(x) cout<<#x<<" having "<<x<<endl
using namespace std;
typedef long double ld;typedef long long ll;
typedef vector<int> vi;typedef vector<pair<int,int>> vpi;typedef vector<vi> vvi;
typedef vector<ll> vll;typedef vector<pair<ll,ll>> vpll;typedef vector<vll> vvll;
template<class T>bool uin(T &a,T b){return a>b?(a=b,true):false;}
template<class T>bool uax(T &a,T b){return a<b?(a=b,true):false;}
const ll MOD=1e9+7,INF=1e18;
/********************************************************************************/

int32_t main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);
    cout.precision(10);cout<<fixed;
#ifndef ONLINE_JUDGE
    freopen("input.txt","rt",stdin);
#endif

    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n==2) cout<<"2"<<endl;
        else if(n%2==0) cout<<"0"<<endl;
        else cout<<"1"<<endl;
    }

#ifndef ONLINE_JUDGE
    cerr<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
#endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n!=0)
    {
        int t;
        cin>>t;
        if(t==1)
            cout<<"3"<<endl;
        else if(t==2)
            cout<<"2"<<endl;
        else
        cout<<t%2<<endl;
        n--;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n!=0)
    {
        int t,a;
        cin>>t;
        if(t==1)
            cout<<"3"<<endl;
        else if(t==2)
            cout<<"2"<<endl;
        else
        cout<<t%2;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n!=0)
    {
        int t,a;
        cin>>t;
        if(t==1)
            cout<<"3"<<endl;
        else if(t==2)
            cout<<"2"<<endl;
        else
        cout<<t%2;
        n--;
    }
    return 0;
}


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

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a,b,c;
        if(n==1)
            cout<<1<<endl;
        else if(n==2)
            cout<<2<<endl;
        else
        {
        c=ceil((float)n/2);
        a=floor((float)c/2);
        b=c-a;

        if((a+b+c)>n)
            cout<<a+b+c-n<<endl;
        else cout<<0<<endl;
        }

    }
    return 0;
}


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

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a,b,c;
        if(n==1)
            cout<<1<<endl;
        else if(n==2)
            cout<<2<<endl;
        else
        {
        c=ceil(1.0*n/2);
        a=floor(1.0*c/2);
        b=c-a;

        if((a+b+c)>n)
            cout<<a+b+c-n<<endl;
        else cout<<0<<endl;
        }

    }
    return 0;
}


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

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a,b,c;
        if(n==1)
            cout<<1<<endl;
        else if(n==2)
            cout<<2<<endl;
        else
        {
        c=ceil((1.0)*n/2);
        a=floor((1.0)*c/2);
        b=c-a;

        if((a+b+c)>n)
            cout<<a+b+c-n<<endl;
        else cout<<0<<endl;
        }

    }
    return 0;
}


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

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a,b,c;
        c=ceil((float)n/2);

        a=floor((float)c/2);

        b=c-a;

        if((a+b+c)>n)
            cout<<a+b+c-n<<endl;
        else cout<<0<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int t;
     cin>>t;
     while(t--)
     {
     	int a;

     	cin>>a;
     	if(a==2)
     	{
     		cout<<2<<endl;
     		continue;
     	}
     	cout<<a%2<<endl;
     }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int t;
     cin>>t;
     while(t--)
     {
     	int a;

     	cin>>a;
     	if(a==2)
     	{
     		cout<<2<<endl;
     		continue;
     	}
     	cout<<min(a%2,a%3)<<endl;
     }
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> q;
    while(q--){
    	int n;
    	cin >> n;
    	if(n<=2) cout << 2 << "\n";
    	else if(n==3) cout << 0 << "\n";
    	else cout << n%2 << "\n";
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> q;
    while(q--){
    	int n,ans = 0;
    	cin >> n;
    	if(n<4) cout << 4-n << "\n";
    	else if(n%2==0) cout << 0 << "\n";
    	else cout << 1 << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> q;
    while(q--){
    	int n;
    	cin >> n;
    	if(n<=4) cout << n%4 << "\n";
    	else cout << n%2 << "\n";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int q;
    long long int n,a,ans;
    cin>>q;
    while(q--){
        cin>>n;
        if(n==1){
            ans = 3;
        }
        else if(n==2)
            ans = 2;
        else{
            if(n&1)
                ans = 1;
            else
                ans = 0;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int q;
    long long int n,a,ans;
    cin>>q;
    while(q--){
        cin>>n;
        if(n==2)
            ans = 2;
        else if(n==3)
            ans = 0;
        else{
            a = (n-1)/2;
            double a2 = double(n-1)/2.0;
            if(a2>a)
                a += 1;
            ans = n - 2*a;
        }
        cout<<ans<<endl;
    }
    return ans;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int q;
    long long int n,a,ans;
    cin>>q;
    while(q--){
        cin>>n;
        if(n==2)
            ans = 2;
        else if(n==3)
            ans = 0;
        else{
            a = (n-1)/2;
            double a2 = double(n-1)/2.0;
            if(a2>a)
                a += 1;
            ans = n - 2*a;
        }
        cout<<ans<<endl;
    }
    return 0;
}


/**< 20-11-2019 */

#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define shL(a,b) ((a)<<(b))
#define shR(a,b) ((a)>>(b))
#define sz(x) (int(x.size()))
#define for1(i,a,b) for (int i=(a),_b=(b);i<=_b;++i)
#define for2(i,a,b) for (int i=(a),_b=(b);i<_b;++i)

using namespace std;

typedef long double ld;
typedef pair<int,int> pii;
typedef pair<short,short> pss;
typedef pair<int64_t,int64_t> pll;
const double PI = acos(-1);

void OFAST(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
}

/////////////////////////////////////////////////////////////////////////////////

int main(){
    #ifndef ONLINE_JUDGE
    freopen("Input","r",stdin);
    //freopen("Output","w",stdout);
    #endif // ONLINE_JUDGE
    short q;
    int n;
    OFAST();
    cin>>q;
    while(q--){
        cin>>n;
        if (n==2) cout<<2<<endl;
        else
        if (n&1){
            if (n%3==0) cout<<0<<endl;
            else cout<<1<<endl;
        }else cout<<0<<endl;
    }

}


/**< 20-11-2019 */

#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define shL(a,b) ((a)<<(b))
#define shR(a,b) ((a)>>(b))
#define sz(x) (int(x.size()))
#define for1(i,a,b) for (int i=(a),_b=(b);i<=_b;++i)
#define for2(i,a,b) for (int i=(a),_b=(b);i<_b;++i)

using namespace std;

typedef long double ld;
typedef pair<int,int> pii;
typedef pair<short,short> pss;
typedef pair<int64_t,int64_t> pll;
const double PI = acos(-1);

void OFAST(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
}

/////////////////////////////////////////////////////////////////////////////////

int main(){
    #ifndef ONLINE_JUDGE
    freopen("Input","r",stdin);
    //freopen("Output","w",stdout);
    #endif // ONLINE_JUDGE
    short q;
    int n;
    OFAST();
    cin>>q;
    while(q--){
        cin>>n;
        if (n==2) cout<<2<<endl;
        else
        if (n&1)cout<<1<<endl;
        else cout<<0<<endl;
    }

}


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

int main(){
    int t;
    cin>>t;
    for (int i = 0; i < t; i++)
    {
        int n;
    cin>>n;
    if(n==2){
        cout<<2<<"\n";
    }
    else
    {
        cout<<n%2<<"\n";
    }
    }

    return 0;
}


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

int main(){
    int t;
    cin>>t;
    for (int i = 0; i < t; i++)
    {
        int n;
    cin>>n;
    if(n==2){
        cout<<2<<"\n";
    }
    else
    {
        cout<<n%2;
    }
    }

    return 0;
}


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

int main(){
    int n;
    cin>>n;
    if(n==2){
        cout<<2<<"\n";
    }
    else
    {
        cout<<n%2;
    }

    return 0;
}


#include <bits/stdc++.h>
#define Im using
#define Too_Stupid_To namespace
#define Solve_This_Problem std
Im Too_Stupid_To Solve_This_Problem;

int main(){
  int t;
  cin >> t;
  while(t--){
  int n;
  cin >> n;
  if (n<=2) cout << n << endl;
  else cout << (n%2==0? 0 : 1) << endl;
  }
}


#include <bits/stdc++.h>
#define Im using
#define Too_Stupid_To namespace
#define Solve_This_Problem std
Im Too_Stupid_To Solve_This_Problem;

int main(){
  int n;
  cin >> n;
  if (n<=2) cout << n << endl;
  else cout << (n%2==0? 0 : 1) << endl;
}


#include<bits/stdc++.h>
using namespace std;
int q, n;
int main()
{
	cin>>q;
	int a, b, c;
	while(q--){
		cin>>n;
		a=n/4;
		b=n/4;
		c=n-a-b;
		int ans=n%4;
		if(ans==3)ans=1;
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int q;
long long n;
int main()
{
	cin>>q;
	long long a, b, c;
	while(q--){
		cin>>n;
		if(n==2){
			cout<<2<<endl;
			continue;
		}
		a=n/4;
		b=n/4;
		c=n-a-b;
		int ans=n%4;
		if(ans>=2)ans-=2;
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int q, n;
int main()
{
	cin>>q;
	int a, b, c;
	while(q--){
		cin>>n;
		a=n/3;
		b=n/3;
		c=n-a-b;
		int ans = max(c, a+b)-min(c, a+b);
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define pb push_back
# define F first
# define S second
# define pll pair<long,long>
# define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n,i,j,k;
        cin>>n;
        if(n<=3)
        {
            cout<<4-n<<endl;
        }
        else if(n%2==0)
        cout<<0<<endl;
        else
        cout<<1<<endl;

    }


#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define pb push_back
# define F first
# define S second
# define pll pair<long,long>
# define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n,i,j,k;
        cin>>n;
        if(n<=3)
        {
            cout<<4-n<<endl;
        }
        else if(n%2==0)
        cout<<0<<endl;
        else
        cout<<1<<endl;

    }
}


/*
When things go wrong as they sometimes will;
When the road you’re trudging seems all uphill;
When the funds are low, and the debts are high;
And you want to smile, but you have to sigh;
When care is pressing you down a bit
Rest if you must, but don’t you quit.

Success is failure turned inside out;
The silver tint of the clouds of doubt;
And you can never tell how close you are;
It may be near when it seems afar.
So, stick to the fight when you’re hardest hit –
It’s when things go wrong that you mustn’t quit.

*/

// ---- My Template start------- //
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long int
#define vv vector
#define desc greater<int>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define gcd(a,b)  __gcd(a,b)
#define setbits(x) __builtin_popcount(x)
#define inf 1e18
#define len(x) x.length()
#define all(v) v.begin(), v.end()
#define fl(i, a, b) for(int i = a; i < b; i++)
#define rfl(i, a, b) for(int i = a; i > b; i--)
#define fll(i, a, b) for(ll i = a; i < b; i++)
#define rfll(i, a, b) for(ll i = a; i > b; i--)
#define fastaf ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
#define cases() int t; cin >> t; while (t--)
#define mod 1000000007

/****************************** FUNCTIONS  ****************************************/
//Modular exponentiation
ll power(ll x, ll y, ll p){
    ll res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

//For M=prime no
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

int phi(int n)
{
    float result = n;
    for (int p = 2; p * p <= n; ++p) {

        if (n % p == 0) {

            while (n % p == 0)
                n /= p;
            result *= (1.0 - (1.0 / (float)p));
        }
    }
    if (n > 1)
        result *= (1.0 - (1.0 / (float)n));

    return (int)result;
}

void openFiles()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void swap(int* a, int* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

//Prime Factorisation
int prime_factor[100000];
vector<pair<int, int> > prime_factors[100000];

void GeneratePrimeFactors(int N)
{

    for(int i = 2; i < N; i++) {
        if(prime_factor[i] != 0)  continue;
        prime_factor[i] = i;
        for(int j = 2*i; j < N; j += i) {
          prime_factor[j] = i;
        }
    }
    for(int i = 2; i < N; i++) {
        int x = i;
        map<int, int> M;
        while(x != 1) {
          M[prime_factor[x]]++;
          x /= prime_factor[x];
        }
        for(auto v : M) {
          prime_factors[i].push_back(v);
        }
    }
}

bool prime[1000007];
void Seive(int N)
{
    memset(prime,true,sizeof(prime));
    for(int i=2;i<=N;i++)
    {
        if(prime[i])
        {
            for(int j=2*i;j<=N;j+=i)
                prime[j]=false;
        }
    }
}

// Matrix Exponentiation
void multiply(ll a[2][2],ll b[2][2])
{
    ll mul[2][2];
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            mul[i][j]=0;
            for(int k=0;k<2;k++)
            {
                mul[i][j]=(mul[i][j] +(a[i][k]%mod * b[k][j]%mod))%mod;
            }
        }
    }
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            a[i][j]=mul[i][j]%mod;
        }
    }
}

void power(ll M[2][2],ll n)
{
    if(n==0 || n==1)
        return;
    ll M1[2][2]={{1,1},{1,0}};
    power(M,n/2);
    multiply(M,M);
    if(n%2!=0)
        multiply(M,M1);
}
ll fib(ll n)
{
    ll M[2][2]={{1,1},{1,0}};
    if(n==0)
        return 0;
    power(M,n-1);
    return M[0][0]%mod;
}

//DSU
vector<int> parent, v_rank;

void make_set(int v){
    parent[v]=v;
    v_rank[v]=0;
}

int find_set(int v){
    if(v==parent[v])
        return v;
    return parent[v]=find_set(parent[v]);
}

void union_sets(int a,int b){
    a=find_set(a);
    b=find_set(b);
    if(a!=b){
        if(v_rank[a]<v_rank[b])
            swap(a,b);
        parent[b]=a;
        if(v_rank[a]==v_rank[b])
            v_rank[a]++;
    }
}

// ------------------------------ My Template end  ------------------------------- //

int main()
{
    fastaf;
    cases()
    {
        int n;
        cin>>n;
        if(n<4){
            cout<<4-n<<endl;
        }
        else if(n%2==0)
            cout<<0<<endl;
        else
            cout<<1<<endl;
    }
    return 0;
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1,n=0,n<0 etc ?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/


/*
When things go wrong as they sometimes will;
When the road you’re trudging seems all uphill;
When the funds are low, and the debts are high;
And you want to smile, but you have to sigh;
When care is pressing you down a bit
Rest if you must, but don’t you quit.

Success is failure turned inside out;
The silver tint of the clouds of doubt;
And you can never tell how close you are;
It may be near when it seems afar.
So, stick to the fight when you’re hardest hit –
It’s when things go wrong that you mustn’t quit.

*/

// ---- My Template start------- //
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long int
#define vv vector
#define desc greater<int>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define gcd(a,b)  __gcd(a,b)
#define setbits(x) __builtin_popcount(x)
#define inf 1e18
#define len(x) x.length()
#define all(v) v.begin(), v.end()
#define fl(i, a, b) for(int i = a; i < b; i++)
#define rfl(i, a, b) for(int i = a; i > b; i--)
#define fll(i, a, b) for(ll i = a; i < b; i++)
#define rfll(i, a, b) for(ll i = a; i > b; i--)
#define fastaf ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
#define cases() int t; cin >> t; while (t--)
#define mod 1000000007

/****************************** FUNCTIONS  ****************************************/
//Modular exponentiation
ll power(ll x, ll y, ll p){
    ll res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

//For M=prime no
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

int phi(int n)
{
    float result = n;
    for (int p = 2; p * p <= n; ++p) {

        if (n % p == 0) {

            while (n % p == 0)
                n /= p;
            result *= (1.0 - (1.0 / (float)p));
        }
    }
    if (n > 1)
        result *= (1.0 - (1.0 / (float)n));

    return (int)result;
}

void openFiles()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void swap(int* a, int* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

//Prime Factorisation
int prime_factor[100000];
vector<pair<int, int> > prime_factors[100000];

void GeneratePrimeFactors(int N)
{

    for(int i = 2; i < N; i++) {
        if(prime_factor[i] != 0)  continue;
        prime_factor[i] = i;
        for(int j = 2*i; j < N; j += i) {
          prime_factor[j] = i;
        }
    }
    for(int i = 2; i < N; i++) {
        int x = i;
        map<int, int> M;
        while(x != 1) {
          M[prime_factor[x]]++;
          x /= prime_factor[x];
        }
        for(auto v : M) {
          prime_factors[i].push_back(v);
        }
    }
}

bool prime[1000007];
void Seive(int N)
{
    memset(prime,true,sizeof(prime));
    for(int i=2;i<=N;i++)
    {
        if(prime[i])
        {
            for(int j=2*i;j<=N;j+=i)
                prime[j]=false;
        }
    }
}

// Matrix Exponentiation
void multiply(ll a[2][2],ll b[2][2])
{
    ll mul[2][2];
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            mul[i][j]=0;
            for(int k=0;k<2;k++)
            {
                mul[i][j]=(mul[i][j] +(a[i][k]%mod * b[k][j]%mod))%mod;
            }
        }
    }
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            a[i][j]=mul[i][j]%mod;
        }
    }
}

void power(ll M[2][2],ll n)
{
    if(n==0 || n==1)
        return;
    ll M1[2][2]={{1,1},{1,0}};
    power(M,n/2);
    multiply(M,M);
    if(n%2!=0)
        multiply(M,M1);
}
ll fib(ll n)
{
    ll M[2][2]={{1,1},{1,0}};
    if(n==0)
        return 0;
    power(M,n-1);
    return M[0][0]%mod;
}

//DSU
vector<int> parent, v_rank;

void make_set(int v){
    parent[v]=v;
    v_rank[v]=0;
}

int find_set(int v){
    if(v==parent[v])
        return v;
    return parent[v]=find_set(parent[v]);
}

void union_sets(int a,int b){
    a=find_set(a);
    b=find_set(b);
    if(a!=b){
        if(v_rank[a]<v_rank[b])
            swap(a,b);
        parent[b]=a;
        if(v_rank[a]==v_rank[b])
            v_rank[a]++;
    }
}

// ------------------------------ My Template end  ------------------------------- //

int main()
{
    fastaf;
    cases()
    {
        int n;
        if(n<4){
            cout<<4-n<<endl;
        }
        else if(n%2==0)
            cout<<0<<endl;
        else
            cout<<1<<endl;
    }
    return 0;
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1,n=0,n<0 etc ?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/


#include <vector>
#include <iostream>
#include <algorithm>

int main()
{
   int n;
   std::cin >> n;
   std::vector<int> v(n, 0);
   std::vector<bool> seen(n, false);
   for (int i = 0; i < n; ++i)
   {
      std::cin >> v[i];
   }
   std::sort(v.begin(), v.end());
   int count = 0;
   for (int i = 0; i < n; ++i)
   {
      if (not seen[i])
      {
         count++;
         seen[i] = true;
         for (int j = i + 1; j < n; ++j)
         {
            if (v[j] % v[i] == 0)
            {
               seen[j] = true;
            }
         }
      }
   }
   std::cout << count << std::endl;
}


#include <iostream>
#include <algorithm>

int main()
{
   int n, i;
   std::cin >> n;
   while(n--)
   {
      std::cin >> i;
      if (i < 4)
         std::cout << 4 - i << std::endl;
      else
         std::cout << i%2 << std::endl;
   }
}


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

int main() {

	int t;
	cin >> t;
	while(t--)
	{
	    ll n;
	    cin >> n;
	    if(n == 2)
	    {
	        cout << 2 << "\n";
	        continue;

	    }
	    if(n == 3)
	    {
	        cout << "0\n";
	    }
	    else if(n%2 == 0)
	    {
	        cout << 0 << "\n";
	    }
	    else
	    {
	        cout << 1 << "\n";
	    }
	}
	return 0;
}


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

int main() {

	int t;
	cin >> t;
	while(t--)
	{
	    ll n;
	    cin >> n;
	    if(n == 2)
	    {
	        cout << 1 << "\n";
	        continue;

	    }
	    if(n == 3)
	    {
	        cout << "0\n";
	    }
	    else if(n%2 == 0)
	    {
	        cout << 0 << "\n";
	    }
	    else
	    {
	        cout << 1 << "\n";
	    }
	}
	return 0;
}


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

int main() {

	int t;
	cin >> t;
	while(t--)
	{
	    ll n;
	    cin >> n;
	    if(n == 2)
	    {
	        cout << 2 << "\n";
	        continue;

	    }

	    else if(n%2 == 0)
	    {
	        cout << 0 << "\n";
	    }
	    else
	    {
	        cout << 1 << "\n";
	    }
	}
	return 0;
}


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

int solve(int n) {
    if (n <= 4) {
        return 4 - n;
    }
    int a = n / 3;
    int rest = n - 2 * a;
    return abs(2 * a - rest);
}

int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in", "r", stdin); freopen("out", "w", stdout);
    #endif
    int q, n;
    cin >> q;
    while (q--) {
        cin >> n;
        cout << solve(n) << endl;
    }

    return 0;
}


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

int solve(int n) {
    if (n <= 4) {
        return 4 - n;
    }
    if (n % 4 == 0) return 0;
    int a = n / 3;
    int rest = n - 2 * a;
    return abs(2 * a - rest);
}

int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in", "r", stdin); freopen("out", "w", stdout);
    #endif
    int q, n;
    cin >> q;
    while (q--) {
        cin >> n;
        cout << solve(n) << endl;
    }

    return 0;
}


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

int solve(int n) {
    if (n % 4 == 0) return 0;
    int a = n / 3;
    int rest = n - 2 * a;
    return abs(2 * a - rest);
}

int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in", "r", stdin); freopen("out", "w", stdout);
    #endif
    int q, n;
    cin >> q;
    while (q--) {
        cin >> n;
        cout << solve(n) << endl;
    }

    return 0;
}


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

int solve(int n) {
    if (n <= 4) return 4 - n;
    if (n % 2 == 0) return 0;
    return 1;
    if (n % 4 == 0) return 0;
    int a = n / 3;
    int rest = n - 2 * a;
    return abs(2 * a - rest);
}

int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in", "r", stdin); freopen("out", "w", stdout);
    #endif
    int q, n;
    cin >> q;
    while (q--) {
        cin >> n;
        cout << solve(n) << endl;
    }

    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<ctgmath>
#include<vector>
#include<algorithm>
#include<ctime>
#define ll long long
#define ld long double
#define pb push_back
#define quluq
#define Amo
#define zard
#define zoha
#define mehkh
#define st stoi
#define gov_baybi_gov
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0)
using namespace std;

const ll N = 1e14 + 1;

map <ll , ll> mp , pm ;
map <char , ll> hs ;
vector <ll> v , vc , ve ,vv , vd ;
deque <char> p , pe ;
deque <string> ts , ss , st , rs ;
deque <double> sd , ds ;
ld q , t , cnt1 , cnt2 ;
string g , s , h , w , o , m , s1 ;
char z , u ;
bool re , rt ;
vector<pair < ll , ll > > pr , rp , pp ;
map < pair < ll , ll > , ll > aw , wa ;
ll  a , b , n , c , f , d , e , cnt = 0  , ans = 0  , rem , temp=0 , minn = 0 ;

int main()
{
    quluq
    zoha
    Amo
    mehkh

        TIME;
        ///AUHTOR AMONULLO MUQIMOV
        ///freopen("input.txt" , "r" , stdin );
        ///freopen("output.txt", "w" , stdout );
        ///Author of the greatest code :: i Amonullo

        cin >> a ;
        for ( ll i = 0 ; i < a ; i ++ )
        {
            cin >> b ;
            if ( b % 2 == 0 )
            {
                if ( b == 2 )
                cout << 2 << endl ;
            else
                cout << 0 << endl ;
            }
        else
            cout << 0 << endl ;
        }

}

///Eco student
///8 is the best


#include<iostream>
#include<bits/stdc++.h>
#include<ctgmath>
#include<vector>
#include<algorithm>
#include<ctime>
#define ll long long
#define ld long double
#define pb push_back
#define quluq
#define Amo
#define zard
#define zoha
#define mehkh
#define st stoi
#define gov_baybi_gov
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0)
using namespace std;

const ll N = 1e14 + 1;

map <ll , ll> mp , pm ;
map <char , ll> hs ;
vector <ll> v , vc , ve ,vv , vd ;
deque <char> p , pe ;
deque <string> ts , ss , st , rs ;
deque <double> sd , ds ;
ld q , t , cnt1 , cnt2 ;
string g , s , h , w , o , m , s1 ;
char z , u ;
bool re , rt ;
vector<pair < ll , ll > > pr , rp , pp ;
map < pair < ll , ll > , ll > aw , wa ;
ll  a , b , n , c , f , d , e , cnt = 0  , ans = 0  , rem , temp=0 , minn = 0 ;

int main()
{
    quluq
    zoha
    Amo
    mehkh

        TIME;
        ///AUHTOR AMONULLO MUQIMOV
        ///freopen("input.txt" , "r" , stdin );
        ///freopen("output.txt", "w" , stdout );
        ///Author of the greatest code :: i Amonullo

        cin >> a ;
        for ( ll i = 0 ; i < a ; i ++ )
        {
            cin >> b ;
            if ( b % 2 == 0 )
            {
                if ( b == 2 )
                cout << 2 << endl ;
            else
                cout << 0 << endl ;
            }
        else
            cout << 1 << endl ;
        }

}

///Eco student
///8 is the best


#include<iostream>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n<4)
        cout<<4-n<<endl;
        else if(n%2)
        cout<<1<<endl;
        else
        cout<<0<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int q;
    cin>>q;
    while(q--){
        int n;
        if(n<4)
        cout<<n-4<<endl;
        else if(n%2)
        cout<<1<<endl;
        else
        cout<<0<<endl;
    }
    return 0;
}


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

int main()
{
  #define int long long
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        if(n==2)cout<<2<<endl;
        else if(n%2!=0)cout<<1<<endl;
        else
        {
            cout<<0<<endl;
        }
    }

}


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

int main()
{
  #define int long long
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        if(n%2!=0)cout<<1<<endl;
        else
        {
            if((n/2)%2==0)cout<<0<<endl;
            else cout<<2<<endl;
        }
    }

}


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

int main()
{
  #define int long long
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        if(n%2!=0)cout<<1<<endl;
        else
        {
            cout<<n%4<<endl;
        }
    }

}


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

int main(){
    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n==2){
            cout<<2<<endl;
        }
        else{
            if(n%4==1){
                cout<<1<<endl;
            }
            else{
                cout<<0<<endl;
            }
        }
    }
    return 0;
}


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

int main(){
    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n%4==1 || n%4==3){
            cout<<1<<endl;
        }
        else if(n%2==2){
            cout<<2<<endl;
        }
        else{
            cout<<0<<endl;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;

int main() {
	int q,n;
	cin>>q;
	while(q--) {
		cin>>n;
		if(n<=4) {
			cout<<(4-n)<<endl;
		} else {
			if(n%2==0) {
				cout<<0<<endl;
			}
			else {
				cout<<1<<endl;
			}
		}
	}
	return 0;
}


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

int main(){
    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n==2){
            cout<<2<<endl;
        }
        else{
            if(n%4==0){
                cout<<0<<endl;
            }
            else{
                cout<<1<<endl;
            }
        }
    }
    return 0;
}


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

int main(){
    int q;
    cin>>q;
    while(q--){
        int n;
        cin>>n;
        if(n%4==1 || n%4==3){
            cout<<1<<endl;
        }
        else if(n%4==2){
            cout<<2<<endl;
        }
        else{
            cout<<0<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int t;
	cin>>t;
	while(t>=0)
	{

	long int n;
	cin>>n;
	long int p,j;
	p=n/4;
	j=n%4;
	if(n<4)
	{
		cout<<4-n<<"\n";
	}
	else
	{
		if(j==2 || j==0)
		{
			cout<<0<<"\n";
		}
		else
		{
			cout<<1<<"\n";
		}
	}
	t--;
}
}


import java.util.Scanner;

public class FlagDay
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int m = input.nextInt();
		int[] dancer = new int[3];
		int[] res = new int[n];
		for (int i = 0; i < n; ++i)
		{
			res[i] = -1;
		}
		boolean[] visited = new boolean[3];
		int idx;
		for (int i = 0; i < m; ++i)
		{
			for (int j = 0; j < 3; ++j)
			{
				visited[j] = false;
			}
			for (int j = 0; j < 3; ++j)
			{
				dancer[j] = input.nextInt();
				if (res[dancer[j] - 1] != -1)
				{
					visited[res[dancer[j] - 1] - 1] = true;
				}
			}
			idx = 0;
			for (int j = 0; j < 3; ++j)
			{
				if (res[dancer[j] - 1] == -1)
				{
					while (visited[idx])
					{
						++idx;
					}
					visited[idx] = true;
					res[dancer[j] - 1] = idx + 1;
				}
			}
		}
		for (int i = 0; i < n; ++i)
		{
			System.out.print(res[i]);
			if (i == n - 1)
			{
				System.out.println();
			}
			else
			{
				System.out.print(" ");
			}
		}
	}
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;

public class palin {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(System.out);
		Scanner scan = new Scanner(System.in);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int n = in.nextInt(), m = in.nextInt(), a[] = new int[n];
		for (int i = 0; i < m; i++) {
			int p = in.nextInt() - 1, q = in.nextInt() - 1, r = in.nextInt() - 1;
			if (a[p] == 0) {
				if (a[q] != 1 && a[r] != 1) {
					a[p] = 1;
				} else {
					if (a[q] != 2 && a[r] != 2) {
						a[p] = 2;
					} else {
						a[p] = 3;
					}
				}
			}
			if (a[q] == 0) {
				if (a[p] != 1 && a[r] != 1) {
					a[q] = 1;
				} else {
					if (a[p] != 2 && a[r] != 2) {
						a[q] = 2;
					} else {
						a[q] = 3;
					}
				}
			}
			if (a[r] == 0) {
				if (a[q] != 1 && a[p] != 1) {
					a[r] = 1;
				} else {
					if (a[q] != 2 && a[p] != 2) {
						a[r] = 2;
					} else {
						a[r] = 3;
					}
				}
			}
		}
		for (int i = 0; i < a.length; i++) {
			out.print(a[i]);
			if (i < a.length - 1) {
				out.print(" ");
			}
		}
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public float nextFloat() {
		return Float.parseFloat(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


import java.io.*;

public class B {
	public static void main(String[] args) throws IOException {
		Parser in = new Parser(System.in);
		PrintStream out = new PrintStream(System.out);
		int n = in.nextInt();
		int[] d = new int[n+1];
		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();
			if (d[a] == 0) {
				if (d[b] == 0) {
					if (d[c] == 0) {
						d[a] = 1;
						d[b] = 2;
						d[c] = 3;
					} else if (d[c] == 1) {
						d[a] = 2;
						d[b] = 3;
					} else if (d[c] == 2) {
						d[a] = 1;
						d[b] = 3;
					} else if (d[c] == 3) {
						d[a] = 1;
						d[b] = 2;
					}
				} else if (d[b] == 1) {
					d[a] = 2;
					d[c] = 3;
				} else if (d[b] == 2) {
					d[a] = 1;
					d[c] = 3;
				} else if (d[b] == 3) {
					d[a] = 1;
					d[c] = 2;
				}
			} else if (d[a] == 1) {
				d[b] = 2;
				d[c] = 3;
			} else if (d[a] == 2) {
				d[b] = 1;
				d[c] = 3;
			} else if (d[a] == 3) {
				d[b] = 1;
				d[c] = 2;
			}
		}
		for (int i = 1; i <= n; i++)
			System.out.print(d[i] + " ");
	}
}

class Parser {
	public Parser (InputStream in) {
		this.in = new DataInputStream(in);
	}

	public int nextInt() throws IOException {
		int c;
		while ((c = in.read()) != '-' && (c > '9' || c < '0'));
		boolean neg = c == '-';
		if (neg) c = in.read();
		int r = 0;
		while (c <= '9' && c >= '0') {
			r = r*10 + c - '0';
			c = in.read();
		}
		return r;
	}

	public String nextName() throws IOException {
		int c;
		while (((c = in.read()) > 'Z' || c < 'A') && (c < 'a' || c > 'z'));
		String s = "";
		while (c <= 'Z' && c >= 'A' || c >= 'a' && c <= 'z') {
			s += (char)c;
			c = in.read();
		}
		return s;
	}

	DataInputStream in;
}


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        try {
            if (new File("input.txt").exists())
                System.setIn(new FileInputStream("input.txt"));
        } catch (SecurityException e) {
        }
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    private void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        int n = nextInt();
        int m = nextInt();

        int a[][] = new int[m][3];
        int ok[] = new int[n+1];
        fill(ok,0);

        for(int i = 0;i < m;i++){
            a[i][0] = nextInt();
            a[i][1] = nextInt();
            a[i][2] = nextInt();
        }

        for(int i = 0;i < m;i++){
            if((ok[a[i][0]]==0)&&(ok[a[i][1]]==0)&&(ok[a[i][2]]==0)){
                ok[a[i][0]]=1;
                ok[a[i][1]]= 2;
                ok[a[i][2]]=3;
            }
            else{
                if((ok[a[i][0]]!=0)){
                    ok[a[i][1]]= (ok[a[i][0]])%3+1;
                    ok[a[i][2]]=(ok[a[i][0]]+1)%3+1;
                }
                else{
                    if((ok[a[i][1]]!=0)){
                        ok[a[i][0]]= (ok[a[i][1]])%3+1;
                        ok[a[i][2]]=(ok[a[i][1]]+1)%3+1;;
                    }
                    else{
                        ok[a[i][0]]= (ok[a[i][2]])%3+1;
                        ok[a[i][1]]=(ok[a[i][2]]+1)%3+1;;
                    }
                }
            }
        }

        for(int i = 1;i <n;i++){
            out.print(ok[i]+" ");
        }
        out.print(ok[n]);

        in.close();
        out.close();
    }

    void chk(boolean b) {
        if (b)
            return;
        System.out.println(new Error().getStackTrace()[1]);
        exit(999);
    }
    void deb(String fmt, Object... args) {
        System.out.printf(Locale.US, fmt + "%n", args);
    }
    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }
    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }
}


import java.util.Scanner;

public class B {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt(); int m = s.nextInt();
		int[] c = new int[n+1];
		for(int i = 0; i < m; i++) {
			int d1 = s.nextInt(); int d2 = s.nextInt(); int d3 = s.nextInt();
			if(c[d1] != 0) {
				c[d2] = (c[d1]+1)%3+1;
				c[d3] = (c[d2]+1)%3+1;
			}
			else if(c[d2] != 0) {
				c[d3] = (c[d2]+1)%3+1;
				c[d1] = (c[d3]+1)%3+1;
			}
			else if(c[d3] != 0) {
				c[d1] = (c[d3]+1)%3+1;
				c[d2] = (c[d1]+1)%3+1;
			}
			else {
				c[d1] = 1; c[d2] = 2; c[d3]	= 3;
			}
		}
		for(int i = 1; i <= n; i++)
			System.out.print(c[i] + " ");
	}

}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package programminginjava;
import java.io.*;
import java.util.*;

/**
 *
 * @author vijit
 */
public class jeff2 {

    static String[] lines;
    static boolean debug;

    public static void assignColor(int[] arr, int person, int[] colorArr){
        if(colorArr[person] != -1) return;
        for(int i=0; i<3; i++){
            if(arr[i] == 0){
                colorArr[person] = i;
                arr[i] = 1;
                return;
            }
        }
    }
    public static void main(String [] args) throws IOException {
        BufferedReader f =  new BufferedReader(new InputStreamReader(System.in));
       // BufferedReader f = new BufferedReader(new FileReader("concom.in"));
       // out = new PrintWriter(new BufferedWriter(new FileWriter("prefix.out")));

        lines = f.readLine().split(" ") ;
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);
        int[] colorArr = new int[n + 1];
        for(int i=0; i<=n; i++){
            colorArr[i] = -1;
        }
        int a,b,c;
        debug = false;
        for(int i=0; i<m; i++){
            //if(i==16) debug = true;
            //else debug = false;
            int[] arr = {0,0,0};
            lines = f.readLine().split(" ");
            a = Integer.parseInt(lines[0]); if(colorArr[a] != -1){arr[colorArr[a]] = 1;}
            b = Integer.parseInt(lines[1]); if(colorArr[b] != -1){arr[colorArr[b]] = 1;}
            c = Integer.parseInt(lines[2]); if(colorArr[c] != -1){arr[colorArr[c]] = 1;}
            if(debug) System.out.println(Arrays.toString(arr));
            assignColor(arr, a, colorArr);  if(debug) System.out.println(Arrays.toString(arr));
            assignColor(arr, b, colorArr);  if(debug) System.out.println(Arrays.toString(arr));
            assignColor(arr, c, colorArr);
        }

        for(int i=1; i<=n; i++){
            System.out.print(colorArr[i] + 1);
            if(i!=n) System.out.print(" ");
        }
        System.out.print("\n");

        //out.close();
        System.exit(0);

    }

}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package programminginjava;
import java.io.*;
import java.util.*;

/**
 *
 * @author vijit
 */
public class jeff2 {

    static String[] lines;

    public static void assignColor(int[] arr, int person, int[] colorArr){
        if(colorArr[person] != -1) return;
        for(int i=0; i<3; i++){
            if(arr[i] == 0){
                colorArr[person] = i;
                arr[i] = 1;
                return;
            }
        }
    }
    public static void main(String [] args) throws IOException {
        BufferedReader f =  new BufferedReader(new InputStreamReader(System.in));
       // out = new PrintWriter(new BufferedWriter(new FileWriter("prefix.out")));

        lines = f.readLine().split(" ") ;
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);
        int[] colorArr = new int[n + 1];
        for(int i=0; i<n; i++){
            colorArr[i] = -1;
        }
        int a,b,c;
        for(int i=0; i<m; i++){
            int[] arr = {0,0,0};
            lines = f.readLine().split(" ");
            a = Integer.parseInt(lines[0]); if(colorArr[a] != -1){arr[colorArr[a]] = 1;}
            b = Integer.parseInt(lines[1]); if(colorArr[b] != -1){arr[colorArr[b]] = 1;}
            c = Integer.parseInt(lines[2]); if(colorArr[c] != -1){arr[colorArr[c]] = 1;}

            assignColor(arr, a, colorArr);
            assignColor(arr, b, colorArr);
            assignColor(arr, c, colorArr);
        }

        for(int i=1; i<=n; i++){
            System.out.print(colorArr[i] + 1);
            if(i!=n) System.out.print(" ");
        }
        System.out.print("\n");

        //out.close();
        System.exit(0);

    }

}


//package hash13;

import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class cf207b
{
    public static void main(String args[]) throws IOException
    {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int dance[] = new int[n];

        int arr[][] = new int[m][3];
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<3;j++)
            {
                arr[i][j] = scan.nextInt();
            }
        }
        Arrays.fill(dance, 0);
        dance[arr[0][0]-1] = 1;
        dance[arr[0][1]-1] = 2;
        dance[arr[0][2]-1] = 3;

        for(int i=1;i<m;i++)
        {
            int colour[] = new int[3];
            Arrays.fill(colour, 0);
            if(dance[arr[i][0]-1] !=0)
            {
                colour[dance[arr[i][0]-1]-1] = 1;
            }
            if(dance[arr[i][1]-1] !=0)
            {
                colour[dance[arr[i][1]-1]-1] = 1;
            }
            if(dance[arr[i][2]-1] !=0)
            {
                colour[dance[arr[i][2]-1]-1] = 1;
            }

            for(int j=0;j<3;j++)
            {
                if(dance[arr[i][j]-1] !=0)
                    continue;
                else
                {
                    int k=0;
                    while(k<3)
                    {
                        if(colour[k]==1)
                        {
                            k++;
                            continue;
                        }
                        else
                        {
                            dance[arr[i][j]-1] = k+1;
                            colour[k] = 1;
                            break;
                        }
                    }
                }
            }
        }

        for(int i=0;i<n;i++)
        {
            System.out.print(dance[i]+" ");
        }
    }
}


import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import java.lang.*;
import java.nio.charset.Charset;

public class B {

    public static void main(String[] args) {
        B a = new B();
        a.run();

    }

    void run(){
            Scanner sc = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out);
            int n = sc.nextInt();
            int m = sc.nextInt();
            int[][] mas = new int[100010][4];
            for (int i = 1; i <= m; i++){
                int a = sc.nextInt();
                int b = sc.nextInt();
                int c = sc.nextInt();
                mas[a][2] = b;
                mas[a][3] = c;
                mas[b][2] = a;
                mas[b][3] = c;
                mas[c][2] = a;
                mas[c][3] = b;
            }
            boolean b= true;
            for (int i = 1; i <= n; i++){
                if ((mas[i][1] == 0) && (mas[mas[i][2]][1] == 0) && (mas[mas[i][3]][1] == 0)){
                    mas[i][1] = 1;
                } else {
                    if ((mas[mas[i][2]][1] != 1) && (mas[mas[i][3]][1] != 1)){
                        mas[i][1] = 1;
                    } else {
                        if ((mas[mas[i][2]][1] != 2) && (mas[mas[i][3]][1] != 2)){
                            mas[i][1] = 2;
                        } else {
                            if ((mas[mas[i][2]][1] != 3) && (mas[mas[i][3]][1] != 3)){
                                mas[i][1] = 3;
                            }
                        }
                    }
                }
            }
            for (int i =1; i <= n; i++){
                out.print(mas[i][1] + " ");
            }
            out.flush();
        }

}


import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import java.lang.*;
import java.nio.charset.Charset;

public class B {

    public static void main(String[] args) {
        B a = new B();
        a.run();

    }

    void run(){
            Scanner sc = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out);
            int n = sc.nextInt();
            int m = sc.nextInt();
            int[] v = new int[100010];
            for (int i = 1; i <= m; i++){
                int a = sc.nextInt();
                int b = sc.nextInt();
                int c = sc.nextInt();
                if ((v[a] == 0) && (v[b] != 1) && (v[c] != 1)){
                    v[a] = 1;
                } else {
                    if ((v[a] == 0) && (v[b] != 2) && (v[c] != 2)) v[a] = 2;
                    else {
                        if (v[a] == 0) v[a] = 3;
                    }
                }
                if ((v[b] == 0) && (v[a] != 1) && (v[c] != 1)){
                    v[b] = 1;
                } else {
                    if ((v[b] == 0) && (v[a] != 2) && (v[c] != 2)) v[b] = 2;
                    else {
                        if (v[b] == 0) v[b] = 3;
                    }
                }
                if ((v[c] == 0) && (v[b] != 1) && (v[a] != 1)){
                    v[c] = 1;
                } else {
                    if ((v[c] == 0) && (v[b] != 2) && (v[a] != 2)) v[c] = 2;
                    else {
                        if (v[c] == 0) v[c] = 3;
                    }
                }
            }
            for (int i = 1; i<= n; i++){
                out.print(v[i] + " ");
            }
            out.flush();
        }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class B {

	public static final int MAX = 1001;

	public static int min_cost(int[] count, int size, int c1, int c2){
		int sum_cost = 0;

		//boolean fst = true;
		for(int i = 0; i < size; i++){
			if(count[i] > 0){
				sum_cost += Math.min(c2, c1 * count[i]);
			}
		}

		return sum_cost;
	}

	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();
		final int m = sc.nextInt();

		int[][] dances = new int[m][3];
		for(int i = 0; i < m; i++){
			for(int j = 0; j < 3; j++){
				dances[i][j] = sc.nextInt() - 1;
			}
		}

		int[] ans = new int[n];
		Arrays.fill(ans, -1);

		for(int i = 0; i < m; i++){
			final boolean fst = ans[dances[i][0]] == -1;
			final boolean snd = ans[dances[i][1]] == -1;
			final boolean thd = ans[dances[i][2]] == -1;

			final int fst_n = ans[dances[i][0]];
			final int snd_n = ans[dances[i][1]];
			final int thd_n = ans[dances[i][2]];

			if(fst && snd && thd){
				ans[dances[i][0]] = 0;
				ans[dances[i][1]] = 1;
				ans[dances[i][2]] = 2;
			}else if(fst && snd){
				ans[dances[i][0]] = (thd_n + 1) % 3;
				ans[dances[i][1]] = (thd_n + 2) % 3;
			}else if(fst && thd){
				ans[dances[i][0]] = (snd_n + 2) % 3;
				ans[dances[i][2]] = (snd_n + 1) % 3;
			}else if(snd && thd){
				ans[dances[i][1]] = (fst_n + 1) % 3;
				ans[dances[i][2]] = (fst_n + 2) % 3;
			}else if(fst){
				for(int t = 0; t < 3; t++){
					if(t != snd_n && t != thd_n){
						ans[dances[i][0]] = t;
						break;
					}
				}
			}else if(snd){
				for(int t = 0; t < 3; t++){
					if(t != fst_n && t != thd_n){
						ans[dances[i][1]] = t;
						break;
					}
				}
			}else if(thd){
				for(int t = 0; t < 3; t++){
					if(t != fst_n && t != snd_n){
						ans[dances[i][2]] = t;
						break;
					}
				}
			}else{

			}
		}

		boolean first = true;
		for(int i = 0; i < n; i++){
			if(first){
				first = false;
			}else{
				System.out.print(" ");
			}
			System.out.print(ans[i] + 1);
		}
		System.out.println();
	}

	public static class Scanner {

		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException{
			br = new BufferedReader(new InputStreamReader(is));
			getLine();
		}

		private void getLine() throws IOException{
			while(tok == null || !tok.hasMoreTokens()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext(){
			return tok.hasMoreTokens();
		}

		public String next() throws IOException{
			if(hasNext()){
				return tok.nextToken();
			}else{
				getLine();
				return tok.nextToken();
			}
		}

		public int nextInt() throws IOException{
			if(hasNext()){
				return Integer.parseInt(tok.nextToken());
			}else{
				getLine();
				return Integer.parseInt(tok.nextToken());
			}
		}

		public long nextLong() throws IOException{
			if(hasNext()){
				return Long.parseLong(tok.nextToken());
			}else{
				getLine();
				return Long.parseLong(tok.nextToken());
			}
		}

		public double nextDouble() throws IOException{
			if(hasNext()){
				return Double.parseDouble(tok.nextToken());
			}else{
				getLine();
				return Double.parseDouble(tok.nextToken());
			}
		}
	}
}


import java.util.Scanner;

public class Codeforces357B {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] colors = new int[n+1];
		for(int i = 0; i < m; i++){
			int a = sc.nextInt();
			int c = sc.nextInt();
			int b = sc.nextInt();
			if(colors[a] != 0){
				if(colors[a] == 2){
					colors[b] = 1;
					colors[c] = 3;
				}
				else{
					colors[b] = 4 - colors[a];
					colors[c] = 2;
				}
			}
			else if(colors[b] != 0){
				if(colors[b] == 2){
					colors[a] = 1;
					colors[c] = 3;
				}
				else{
					colors[a] = 4 - colors[b];
					colors[c] = 2;
				}
			}
			else{
				if(colors[c] % 2 == 0){
					colors[c] = 2;
					colors[a] = 1;
					colors[b] = 3;
				}
				else{
					colors[a] = 4 - colors[c];
					colors[b] = 2;
				}
			}
		}
		System.out.print(colors[1]);
		for(int i = 2; i <= n; i++){
			System.out.printf(" %d",colors[i]);
		}
		System.out.println();
	}
}