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 PYTHON3):

Solution:
import sys
input = sys.stdin.buffer.readline

for _ in range(int(input())):
    x = input()

    n,m = map(int,input().split())

    # kosaraju's algorithm to find sccs and create compressed graph
    adj = [[] for i in range(n+1)]
    radj = [[] for i in range(n+1)]

    # setup adj and radj
    for i in range(m):
        a,b = map(int,input().split())

        adj[a].append(b)
        radj[b].append(a)

    toposort = []
    vis = [0] * (n + 1)
    idx = [0] * (n + 1)
    for c in range(1,n+1):
        if not vis[c]:
            vis[c] = 1
            s = [c]
            while s:
                c = s[-1]

                if idx[c] < len(adj[c]):
                    ne = adj[c][idx[c]]

                    if not vis[ne]:
                        vis[ne] = 1
                        s.append(ne)

                    idx[c] += 1

                else:
                    toposort.append(c)
                    s.pop()
    
    scc = [0]*(n+1)
    sccs = [[]]
    while toposort:
        c = toposort.pop()

        if scc[c] == 0:
            sccs.append([])
        
        s = [c]
        while s:
            c = s.pop()

            if scc[c] == 0:
                scc[c] = len(sccs)-1
                sccs[-1].append(c)

                for ne in radj[c]:
                    if scc[ne] == 0:
                        s.append(ne)

    compressed_adj = [[] for i in range(len(sccs))]
    compressed_radj = [[] for i in range(len(sccs))]
    cycle = [0] * len(sccs)

    for a in range(1,n+1):
        for b in adj[a]:
            if scc[a] != scc[b]:
                compressed_adj[scc[a]].append(scc[b])
                compressed_radj[scc[b]].append(scc[a])
            else:
                # size > 1 of self loop
                cycle[scc[a]] = 1


    # begin to compute answer
    ans = [0]*(n+1)

    for i in range(1,len(sccs)):
        if 1 in sccs[i]:
            start = i

    # find the reachable nodes and put them in reachable cycles
    reachable_cycles = []
    s = [start]

    vis = [0] * (n + 1)
    idx = [0] * (n + 1)
    while s:
        c = s[-1]

        if not vis[c]:
            vis[c] = 1

            if cycle[c]:
                reachable_cycles.append(c)
            else:
                # reachable, but set ans as 1 for now
                # ans could become -1 if a reachable cycle from 1 can reach it or 2 if not, but > 1 path from 1
                for i in sccs[c]:
                    ans[i] = 1

        if idx[c] < len(compressed_adj[c]):
            ne = compressed_adj[c][idx[c]]

            if not vis[ne]:  # so element gets put on stack only 1 time
                s.append(ne)

            idx[c] += 1

        else:
            s.pop()

    # find the reachable nodes from the cycles reachable from 1
    # these have ans = -1
    vis = [0] * (n + 1)
    idx = [0] * (n + 1)
    for c in reachable_cycles:
        s = [c]

        while s:
            c = s[-1]

            if not vis[c]:
                vis[c] = 1

                for i in sccs[c]:
                    ans[i] = -1

            if idx[c] < len(compressed_adj[c]):
                ne = compressed_adj[c][idx[c]]

                if not vis[ne]:  # so element gets put on stack only 1 time
                    s.append(ne)

                idx[c] += 1

            else:
                s.pop()

    # find the # of paths via dp on the dag to see if remaining nodes with ans = 1 are 1 or 2
    paths = [0]*(n+1)
    paths[start] = 1

    vis = [0] * (n + 1)
    idx = [0] * (n + 1)
    for c in range(1, n + 1):
        if ans[c] == 1: # all sccs[c] should be of size 1
            if not vis[scc[c]]:
                vis[scc[c]] = 1
                s = [scc[c]]

                while s:
                    c = s[-1]

                    if len(sccs[c]) > 1:
                        raise RuntimeError

                    if idx[c] < len(compressed_radj[c]):
                        ne = compressed_radj[c][idx[c]]

                        if not cycle[ne] and not vis[ne]:
                            vis[ne] = 1
                            s.append(ne)

                        idx[c] += 1

                    else:
                        for ne in compressed_adj[c]:
                            if not cycle[ne]:
                                paths[ne] += paths[c]

                        s.pop()

    for c in range(1, n + 1):
        if ans[c] == 1:  # all sccs[c] should be of size 1
            ans[c] = 2 if paths[scc[c]] > 1 else 1

    # yay answer
    print(*ans[1:])