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())

    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

    for i in range(1,len(sccs)):
        if not cycle[i] and len(sccs[i]) > 1:
            raise RuntimeError

    ans = [0]*(n+1)

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

    '''
    s = [start]
    
    vis = [0] * (n + 1)
    idx = [0] * (n + 1)
    cycle_on_path = 0 #infinite now
    removed = [0]*(n+1)
    while s:
        c = s[-1]

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

            if cycle[c]:
                cycle_on_path += 1

            for i in sccs[c]:
                if cycle_on_path:
                    ans[i] = -1
                else:
                    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:
            if cycle[c]:
                cycle_on_path -= 1
                removed[c] += 1
                if removed[c] != 1:
                    raise RuntimeError

            s.pop()
    '''

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

    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()

    for i in range(1,n+1):
        if cycle[scc[i]] and not (ans[i] == -1 or  ans[i] == 0):
            raise RuntimeError


    for i in range(1,n+1):
        if len(sccs[scc[i]]) > 1 and ans[i] == 1:
            raise RuntimeError
    for i in range(len(sccs)):
        if len(sccs[i]) > 1:
            for j in sccs[i]:
                if ans[j] == 1:
                    raise RuntimeError

    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

    print(*ans[1:])