Amit has been awarded as the most meritorious student award in school. He is proud of it and decides to further improve his performance in his new college. He has to take N courses. The courses are labelled from 1 to N. Some courses might have prerequisites. For example, to take Data Structure course, one needs to take C Programming course first. There are M such pair denoting the course and it's corresponding prerequisite course which Amit needs to take first in order to successfully finish that particular course.
Given the number of courses he needs to take and a list of prerequisites pair, find out whether it is possible for Amit to finish all the courses and once again prove his mettle.
Input:
The first line of the input contains T denoting the number of test cases.
Each test case contains two non-negative integers N and M denoting the number of courses Amit needs to take and the number of prerequisites pair respectively.
Each of the next M lines contains two distinct positive integers ui and vi denoting the ith prerequisite pair where ui is a prerequisite for vi. It is ensured that the M lines will be pair-wise distinct.
Output:
For each test-case, output 1 if it is possible for Amit to finish all the courses or output 0 if Amit will not be able to complete all the courses.
Constraints:
In the first test case, Amit can finish the courses in the following order: 1,2 & 3.
In the second test case, Course Number 1 depends on course number 2 and vice - versa. Hence, Amit doesn't know which course to take first and hence he cannot finish all the courses.