Under construction

Still being built. Things may change

Evacuation

Time limit1sMemory limit128 MB

Summary
Find the maximum number of queens that can travel from checkpoint 1 to checkpoint N when only roads touching either end carry at most one ant.
Level

Medium7 of 10

Topics
Graph
Solved
No attempts yet

Problem

Most of the ants working in the CC garden died in a sudden disaster, and only 1000 queen ants and a few worker ants survived. To keep the colony alive, the survivors decided to send some of the queens to a shelter. The shelter is very safe, and in a few months the colony will grow there again.

The shelter is laid out like this.

  1. The shelter has NN checkpoints and MM roads that join checkpoints.
  2. If x<yx < y, checkpoint xx sits at a higher altitude than checkpoint yy.
  3. A road always runs from the higher checkpoint to the lower one.
  4. An ant cannot move from a lower checkpoint to a higher one.
  5. Each road that touches checkpoint 11 carries only one ant.
  6. Each road that touches checkpoint NN carries only one ant.
  7. At most one road directly joins two checkpoints uu and vv.

A road that touches neither checkpoint 11 nor checkpoint NN has no limit on how many ants use it, and a checkpoint has no limit on how many ants stay there.

Every queen ant starts at checkpoint 11. A queen that never reaches checkpoint NN does not survive, so the ants want to send as many queens as possible to checkpoint NN. The remaining queens join the defense line.

Find the largest number of queen ants that can reach the shelter.

Input

The first line has the number of test cases TT.

The first line of each test case has the number of checkpoints NN (2≤N≤2002 \le N \le 200) and the number of roads MM (1≤M≤N(N−1)/21 \le M \le N(N-1)/2).

Each of the next MM lines has two integers xx, yy (1≤x<y≤N1 \le x < y \le N), meaning a road runs from checkpoint xx to checkpoint yy.

Output

For each test case, print on one line the largest number of queen ants that can reach checkpoint NN.

Examples1

  1. Example 1

    Input
    3
    7 9
    1 2
    1 3
    1 4
    1 5
    2 6
    3 6
    4 6
    5 6
    6 7
    12 19
    1 3
    1 4
    1 2
    1 5
    2 8
    3 9
    3 7
    4 6
    4 11
    5 8
    6 9
    6 10
    7 10
    7 11
    8 12
    9 10
    9 12
    10 12
    11 12
    4 6
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    
    Expected output
    1
    3
    3