Problem: You are given a directed graph G which can contain loops (edges from a vertex to itself). Multi-edges are absent in G which means that for all ordered pairs (u, v) exists at most one edge from u to v. Vertices are numbered from 1 to n.

A path from u to v is a sequence of edges such that:

  * vertex u is the start of the first edge in the path; 
  * vertex v is the end of the last edge in the path; 
  * for all pairs of adjacent edges next edge starts at the vertex that the previous edge ends on. 



We will assume that the empty sequence of edges is a path from u to u.

For each vertex v output one of four values:

  * 0, if there are no paths from 1 to v; 
  * 1, if there is only one path from 1 to v; 
  * 2, if there is more than one path from 1 to v and the number of paths is finite; 
  * -1, if the number of paths from 1 to v is infinite. 



Let's look at the example shown in the figure.

<image>

Then:

  * the answer for vertex 1 is 1: there is only one path from 1 to 1 (path with length 0); 
  * the answer for vertex 2 is 0: there are no paths from 1 to 2; 
  * the answer for vertex 3 is 1: there is only one path from 1 to 3 (it is the edge (1, 3)); 
  * the answer for vertex 4 is 2: there are more than one paths from 1 to 4 and the number of paths are finite (two paths: [(1, 3), (3, 4)] and [(1, 4)]); 
  * the answer for vertex 5 is -1: the number of paths from 1 to 5 is infinite (the loop can be used in a path many times); 
  * the answer for vertex 6 is -1: the number of paths from 1 to 6 is infinite (the loop can be used in a path many times). 

Input

The first contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Before each test case, there is an empty line.

The first line of the test case contains two integers n and m (1 ≤ n ≤ 4 ⋅ 10^5, 0 ≤ m ≤ 4 ⋅ 10^5) — numbers of vertices and edges in graph respectively. The next m lines contain edges descriptions. Each line contains two integers a_i, b_i (1 ≤ a_i, b_i ≤ n) — the start and the end of the i-th edge. The vertices of the graph are numbered from 1 to n. The given graph can contain loops (it is possible that a_i = b_i), but cannot contain multi-edges (it is not possible that a_i = a_j and b_i = b_j for i ≠ j).

The sum of n over all test cases does not exceed 4 ⋅ 10^5. Similarly, the sum of m over all test cases does not exceed 4 ⋅ 10^5.

Output

Output t lines. The i-th line should contain an answer for the i-th test case: a sequence of n integers from -1 to 2.

Example

Input


5

6 7
1 4
1 3
3 4
4 5
2 1
5 5
5 6

1 0

3 3
1 2
2 3
3 1

5 0

4 4
1 2
2 3
1 4
4 3


Output


1 0 1 2 -1 -1 
1 
-1 -1 -1 
1 0 0 0 0 
1 1 2 1 

Solution (in CPP):

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

typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll>vll;
#define sf scanf
#define pf printf
#define nl printf("\n")
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d%d",&x,&y)
#define siii(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld%lld",&x,&y)
#define slll(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define FOR(i,n) for(int i=0;i<n;i++)
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define chk cerr<<"CAME HERE"<<endl
#define dbug(x) cerr<<"value of "<<#x<<" = "<<x<<endl
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
mt19937 rng((uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
inline int rand(int l, int r){uniform_int_distribution<int> RNG(l,r);return RNG(rng);}

const int N = 4e5+5;


pii dp[N];
vector<int>dag[N];
bool selfloop[N];
bool cmploop[N];
int parent[N];
int cnt[N];

struct tarjanSCC{
	vector<int>graph[N];
	int discovery_time[N];

	int Time=0,scc=0,n;
	stack<int>curTree;
	bool inTree[N];

	void reset(int n){///CALL FIRST
		this->n=n;
		Time=0;
		scc=1;
		while(!curTree.empty())curTree.pop();
		for(int i=0; i<=n; i++){
			discovery_time[i]=0;
			parent[i]=0;
			graph[i].clear();
			cmploop[i]=0;
			selfloop[i]=0;
			cnt[i]=0;
			dp[i]={-1,0};
			inTree[i]=0;
			dag[i].clear();
		}
	}

	void addEdge(int u, int v){graph[u].push_back(v);}
	void run(){for(int i=1; i<=n; i++)if(!discovery_time[i])dfs(i);}
	
	void makedag(){
		for(int i=1; i<=n; i++){
			if(selfloop[i])cmploop[parent[i]]=1;
			for(int v:graph[i]){
				if(parent[i]!=parent[v])
					dag[parent[v]].push_back(parent[i]);
			}
		}
	}
	int dfs(int u){
		int low=discovery_time[u]=++Time;
		curTree.push(u);
		inTree[u]=1;

		for(int v:graph[u]){
			if(!discovery_time[v])low=min(low,dfs(v));
			else if(inTree[v])low=min(low,discovery_time[v]);
		}
		
		if(low==discovery_time[u]){
			int top;
			do{
				top=curTree.top();
				curTree.pop();
				cnt[scc]++;
				inTree[top]=0;
				parent[top]=scc;
			}while(u!=top);
			scc++;
		}
		return low;
	}
	
}scc;


int target;

pii f(int u){
	if(u==target)return pii(1,cmploop[u] || cnt[u]>1);
	pii &ret = dp[u];
	if(ret.first!=-1)return ret;
	ret=pii(0,cmploop[u] || cnt[u]>1);
	for(int v:dag[u]){
		pii x = f(v);
		ret.first+=x.first;
		if(x.first>0)ret.second|=x.second;
		if(ret.first>=2)ret.first=2;
	}
	return ret;
}


void solve(int casenum){
	int n,m;
	sii(n,m);
	scc.reset(n);
	for(int i=0,u,v; i<m; i++){
		sii(u,v);
		if(u==v)selfloop[u]=1;
		else scc.addEdge(u,v);
	}
	
	scc.run();
	scc.makedag();
	target=parent[1];

	
	for(int i=1; i<=n; i++){
		int x = parent[i];
		//dbug(x);
		//pf("zzfsd %d %d %d %d %d\n",i,parent[i],cnt[x],cnt2[x],cnt3[x]);
		pii p = f(x);
		if(p.first==0)pf("0 ");
		else {
			if(p.second)pf("-1 ");
			else if(p.first>1)pf("2 ");
			else pf("1 ");
		}
	}
	nl;
	scc.reset(n);
}

int main(){
	
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int T=1;
    scanf("%d",&T);
    //cin>>T;
    for(int i=1; i<=T; i++)
        solve(i);

return 0;
}