Welcome to ZOJ
 Problem Sets Information Select Problem Runs Ranklist
ZOJ Problem Set - 4124
Median

Time Limit: 1 Second      Memory Limit: 65536 KB

Recall the definition of the median of $n$ elements where $n$ is odd: sort these elements and the median is the $\frac{(n+1)}{2}$-th largest element.

In this problem, the exact value of each element is not given, but $m$ relations between some pair of elements are given. The $i$-th relation can be described as $(a_i, b_i)$, which indicates that the $a_i$-th element is strictly larger than the $b_i$-th element.

For all $1 \le k \le n$, is it possible to assign values to each element so that all the relations are satisfied and the $k$-th element is the median of the $n$ elements?

#### Input

There are multiple test cases. The first line of the input contains an integer $T$, indicating the number of test cases. For each test case:

The first line contains two integers $n$ and $m$ ($1 \le n < 100$, $1 \le m \le n^2$), indicating the number of elements and the number of relations. It's guaranteed that $n$ is odd.

For the following $m$ lines, the $i$-th line contains two integers $a_i$ and $b_i$, indicating that the $a_i$-th element is strictly larger than the $b_i$-th element. It guaranteed that for all $1 \le i < j \le m$, $a_i \ne a_j$ or $b_i \ne b_j$.

It's guaranteed that the sum of $n$ of all test cases will not exceed $2 \times 10^3$.

#### Output

For each test case output one line containing one string of length $n$. If it is possible to assign values to each element so that all the relations are satisfied and the $i$-th element is the median, the $i$-th character of the string should be '1', otherwise it should be '0'.

#### Sample Input

2
5 4
1 2
3 2
2 4
2 5
3 2
1 1
2 3


01000 000

#### Hint

For the first sample test case, as the 2nd element is smaller than the 1st and the 3rd elements and is larger than the 4th and the 5th elements, it's possible that the 2nd element is the median.

For the second sample test case, as the 1st element can't be larger than itself, it's impossible to assign values to the elements so that all the relations are satisfied.

Author: WANG, Yucheng
Source: The 10th Shandong Provincial Collegiate Programming Contest
Submit    Status