Arthur owns a ski resort on a mountain. There are $n$ landing spots on the mountain numbered from $1$ to $n$ from the top to the foot of the mountain. The spots are connected with one-directional ski tracks. All tracks go towards the foot of the mountain, so there are no directed cycles formed by the tracks. There are at most two tracks leaving each spot, but many tracks may enter the same spot.

A skier can start skiing from one spot and stop in another spot if there is a sequence of tracks that lead from the starting spot and end in the ending spot. Unfortunately, recently there were many accidents, because the structure of the resort allows a skier to go through dangerous paths, by reaching high speed and endangering himself and the other customers. Here, a path is called dangerous, if it consists of at least two tracks.

Arthur wants to secure his customers by closing some of the spots in a way that there are no dangerous paths in the resort. When a spot is closed, all tracks entering and leaving that spot become unusable. 

Formally, after closing some of the spots, there should not be a path that consists of two or more tracks.

Arthur doesn't want to close too many spots. He will be happy to find any way to close at most $\frac{4}{7}n$ spots so that the remaining part is safe. Help him find any suitable way to do so.


-----Input-----

The first line contains a single positive integer $T$ — the number of test cases. $T$ test case description follows.

The first line of each description contains two integers $n$ and $m$ ($1 \leq n \leq 2 \cdot 10^5$) — the number of landing spots and tracks respectively.

The following $m$ lines describe the tracks. Each of these lines contains two integers $x$ and $y$ ($1 \leq x < y \leq n$) — indices of the starting and finishing spots for the respective track. It is guaranteed that at most two tracks start at each spot. There may be tracks in which starting and finishing spots both coincide.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case, print a single integer $k$ ($0 \leq k \leq \frac{4}{7}n$) — the number of spots to be closed. In the next line, print $k$ distinct integers — indices of all spots to be closed, in any order.

If there are several answers, you may output any of them. Note that you don't have to minimize $k$. It can be shown that a suitable answer always exists.


-----Example-----
Input
2
4 6
1 2
1 3
2 3
2 4
3 4
3 4
7 6
1 2
1 3
2 4
2 5
3 6
3 7

Output
2
3 4 
4
4 5 6 7 



-----Note-----

In the first sample case, closing any two spots is suitable.

In the second sample case, closing only the spot $1$ is also suitable.

Difficulty: interview

Starter code:

Solutions:
import sys
input = sys.stdin.readline
for f in range(int(input())):
    n,m=list(map(int,input().split()))
    neig=[0]*n
    for i in range(n):
        neig[i]=[0]
    
    for i in range(m):
        a,b=list(map(int,input().split()))
        a-=1
        b-=1
        neig[a][0]+=1
        neig[a].append(b)
    lev=[1]*n
    for i in range(n):
        for j in range(1,neig[i][0]+1):
            x=lev[i]+1
            if x==4:
                x=1
            lev[neig[i][j]]=max(lev[neig[i][j]],x)
    sol=0
    s=[]
    for i in range(n):
        if lev[i]==3:
            sol+=1
            s.append(i+1)
    print(sol)
    print(*s)
    


import sys
input = sys.stdin.readline
from heapq import heapify,heappush,heappop
t = int(input())
for _ in range(t):
  n,m = map(int,input().split())
  ab = [list(map(int,input().split())) for i in range(m)]
  go = [[] for i in range(n+1)]
  come = [[] for i in range(n+1)]
  for a,b in ab:
    go[a].append(b)
    come[b].append(a)
  exist = [1]*(n+1)
  flg = [10]*(n+1)
  for i in range(1,n+1):
    if flg[i] == 10:
      flg[i] = 2
    if flg[i] == 0:
      exist[i] = 0
    if go[i]:
      if flg[i] == 0:
        for j in go[i]:
          flg[j] = min(flg[j],2)
      else:
        for j in go[i]:
          flg[j] = min(flg[j],flg[i]-1)
  print(exist.count(0))
  ansls = []
  for i in range(1,n+1):
    if exist[i] == 0:
      ansls.append(i)
  print(*ansls)

import sys

T = int(sys.stdin.readline().strip())
for t in range (0, T):
    n, m = list(map(int, sys.stdin.readline().strip().split()))
    P = [[] for i in range (0, n)]
    G = [0] * n
    for i in range (0, m):
        x, y = list(map(int, sys.stdin.readline().strip().split()))
        x, y = x-1, y-1
        P[y].append(x)
    ans = []
    for i in range (0, n):
        for j in P[i]:
            for k in P[j]:
                if G[j] == 0 and G[k] == 0:
                    if G[i] == 0:
                        ans.append(str(i+1))
                        G[i] = 1
                    
    print(len(ans))
    print(" ".join(ans))


import sys
inputr = lambda: sys.stdin.readline().rstrip('\n')
input = sys.stdin.readline

for _ in range(int(input())):
	n, m = list(map(int, input().split()))


	adj = [[] for _ in range(n)]

	for _ in range(m):
		a, b = list(map(int, input().split()))
		a -= 1
		b -= 1
		adj[a].append(b)

	LP = [0] * n

	for i in range(n):
		if LP[i] < 2:
			for j in adj[i]:
				LP[j] = max(LP[j], LP[i] + 1)

	r = [i+1 for i in range(n) if LP[i] >= 2]

	print(len(r))
	print(' '.join(map(str, r)))

	assert 7 * len(r) <= 4 * n



import sys
inputr = lambda: sys.stdin.readline().rstrip('\n')
input = sys.stdin.readline

for _ in range(int(input())):
	n, m = list(map(int, input().split()))
	adj = [[] for _ in range(n)]

	for _ in range(m):
		a, b = list(map(int, input().split()))
		a -= 1
		b -= 1
		adj[a].append(b)

	LP = [0] * n
	r = []

	for i in range(n):
		if LP[i] < 2:
			for j in adj[i]:
				LP[j] = max(LP[j], LP[i] + 1)
		else:
			r.append(str(i+1))

	print(len(r))
	print(*r)

	assert 7 * len(r) <= 4 * n



#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

class DirectedGraph:
    def __init__(self, adj):
        self.n = len(adj)
        self.adj = adj
        self.is_asyclic = False
        self.max_path_len = None

    def topological_sort(self):
        indegree = [0] * self.n
        for vs in self.adj:
            for dest in vs:
                indegree[dest] += 1
        zero_v = []
        for v, indeg in enumerate(indegree):
            if indeg == 0:
                zero_v.append(v)
        max_path_len = 1
        tp_sorted = []
        to_be_added = []
        while True:
            while zero_v:
                v = zero_v.pop()
                tp_sorted.append(v)
                for dest in self.adj[v]:
                    indegree[dest] -= 1
                    if indegree[dest] == 0:
                        to_be_added.append(dest)
            if len(to_be_added) > 0:
                zero_v.extend(to_be_added)
                to_be_added = []
                max_path_len += 1
            else:
                break
        if len(tp_sorted) == self.n:
            self.is_asyclic = True
            self.max_path_len = max_path_len
            return tp_sorted
        else:
            self.is_asyclic = False
            return None

t = int(input())
for case in range(t):
    n, m = map(int, input().split())
    forward = [[] for _ in range(n)]
    backward = [[] for _ in range(n)]

    seen = set()
    for _ in range(m):
        u, v = map(int, input().split())
        u -= 1; v -= 1
        if (u, v) in seen:
            continue
        seen.add((u, v))
        forward[u].append(v)
        backward[v].append(u)
    
    DG = DirectedGraph(forward)
    tps = DG.topological_sort()
    state = [-1] * n
    state[0] = 0
    for v in tps:
        if len(backward[v]) == 0:
            state[v] = 0
        for pv in backward[v]:
            state[v] = max(state[v], (state[pv] + 1) % 3)
    
    ans = []
    for i, color in enumerate(state):
        if color == 2:
            ans.append(i + 1)
    print(len(ans))
    print(*ans)

import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')


def solve(n, m, g):
    dp = [0] * n
    ans = []
    for i in range(n):
        for w in g[i]:
            dp[i] = max(dp[i], dp[w] + 1)
        if dp[i] >= 2:
            dp[i] = -1
            ans.append(i+1)
    wi(len(ans))
    wia(ans)


def main():
    for _ in range(ri()):
        n, m = ria()
        g = [[] for i in range(n)]
        for __ in range(m):
            u, v = ria()
            g[v-1].append(u-1)
        solve(n, m, g)


def __starting_point():
    main()

__starting_point()