Median Weight Bead#4688

Median Weight Bead

1 second
32 megabytes
Medium

There are beads, all of the same shape and size, but with different weights. is an odd number, and the beads are labeled as 1, 2, \ldots, N. Your task is to find the bead whose weight is the median (the \left(\frac{N+1}{2}\right)-th among all beads). The following comparison has been performed on some pairs of beads:

A balance scale is available to compare the weights of beads. With it, you can determine which of two beads is heavier. As a result, you now know that some beads are heavier than others. You are going to remove some beads which cannot possibly have the median weight.

For example, the following results show which bead is heavier after comparisons, where M=4 and N=5:

  1. Bead is heavier than bead .

  2. Bead is heavier than bead .

  3. Bead is heavier than bead .

  4. Bead is heavier than bead .

From these results, even though we cannot determine exactly which bead has the median weight, we know that beads and can never have the median weight: beads , , and are heavier than bead , and beads , , and are lighter than bead . Therefore, we can remove these two beads from consideration.

Write a program to count the number of beads which cannot possibly have the median weight.

Input

The first line contains a single integer (1 \leq t \leq 11), the number of test cases.

Each test case is described as follows:

The first line contains two integers (1 \leq N \leq 99), the number of beads, and , the number of comparisons made. Each of the next lines contains two integers, where the first bead is heavier than the second bead.

Output

For each test case, print the number of beads which cannot possibly have the median weight, on a separate line.

Examples

Example 1

Loading
Loading