Bureaucracy is synonymous with boredom, but you will have no choice but to face it if you want to collect your scholarship before the year ends. To this end, you head to the ministerial offices to try your luck with the procedures, to see if you can obtain the necessary supporting document.
There are $$$n$$$ secretarial windows in a row, one behind the other. At each window, you can carry out a procedure, which consists of presenting document A to obtain another document B. The procedure can only be performed if you have document A, and this document is retained after the procedure. However, once you pass a window (whether or not a procedure is performed at it), you cannot go back due to legal subtleties that are not relevant here. Once you pass the last window, it will no longer be possible to return to the first, as the offices will have closed.
Initially, you have only one document. Given the initial document and the desired one, what is the minimum number of procedures possible?
The input starts with an integer $$$T$$$, the number of test cases. Each case begins with $$$n$$$ and $$$m$$$, the number of windows and the total number of documents that exist. The documents are numbered from $$$0$$$ to $$$m-1$$$, with $$$0$$$ being the initial document and $$$m-1$$$ being the desired document. Following are $$$n$$$ lines with two integers $$$a_i$$$ $$$b_i$$$, indicating that at the $$$i$$$-th window, document $$$a_i$$$ can be presented to obtain document $$$b_i$$$.
For each case, print a line with the minimum number of procedures to be performed. If it is impossible to obtain the desired document, print "Imposible" instead (without quotes).
Case 1 (5 points): $$$1 \leq n \leq 10^3$$$, $$$m = 2$$$.
Case 2 (5 points): $$$n = 2$$$, $$$1 \leq m \leq 10^3$$$.
Case 3 (36 points): $$$1 \leq n,m \leq 10^3$$$.
Case 4 (54 points): $$$1 \leq n,m \leq 10^6$$$.
4 2 3 0 1 1 2 2 3 0 2 1 0 2 4 1 3 0 1 6 7 0 3 3 2 4 6 3 5 2 5 5 6
2 1 Imposible 3
| Name |
|---|


