The first line contains a number T(1 <= T <= 10), denoting the number of testcases.
For each testcase, the first line contains two space-seperated integers n and m(3 <= n <= 10^5, 1 <= m <= 10^9), representing the number of vertices in the graph and the number of colors you have.
Then, n lines follow. The i-th of them contains an integer f_i, denoting a directed edge from vertice i to vertice f_i in the given graph.(1 <= f_i <= n, f_i != i)