Under construction

Still being built. Things may change

White Collar

Interview

Time limit1sMemory limit1024 MB

Summary
Given a map of one-way roads, list every city that lies on some shortest path from city 1 to city N.
Level

Medium4 of 10

Topics
Shortest path, BFS, Graph
Solved
No attempts yet

Problem

The top con artist in America, Neil Caffrey has pulled off every kind of theft and fraud there is. Tonight he plans to steal the Music Box, one of the finest works of art in the world.

This morning, AdbyMe, Inc. learned of the plan and is designing an operation to catch him. AdbyMe knows which city Neil is in now and which city holds the Music Box, and it will station agents to catch him. According to its intelligence, Neil is in a great hurry, so he will take the shortest path from his current location to the Music Box.

So AdbyMe plans to station agents in the city where Neil is now, the city with the Music Box, and every city he might pass through on the way. Look at the map and pick out every city where agents should be placed.

Input

The input consists of TT test cases. The first line contains TT.

The first line of each test case contains the number of cities NN (2≤N≤10002 \le N \le 1000) and the number of roads MM (1≤M≤500001 \le M \le 50000). The next MM lines contain the numbers of the connected cities AiA_i and BiB_i. Every road is one-way, going from AiA_i to BiB_i. (1≤Ai,Bi≤N1 \le A_i, B_i \le N, Ai≠BiA_i \ne B_i)

Neil is in city 1, and the Music Box is in city NN. There is always at least one path from city 1 to city NN.

Output

For each test case, print on its own line the numbers of the cities where AdbyMe, Inc. should station agents, in ascending order.

Examples1

  1. Example 1

    Input
    2
    4 5
    1 2
    2 1
    1 3
    3 4
    4 3
    5 6
    1 2
    1 3
    2 5
    3 4
    3 5
    4 5
    
    Expected output
    1 3 4
    1 2 3 5