You are given a graph with ‘N’ nodes and exactly one cycle. You are given a 2-d array ‘EDGES’, where ‘Edges[i]’=[‘node0’, ’node1’], denotes an undirected edge from node0 to node1. The nodes are numbered from 0 to ‘N’-1, where ‘N’ is the number of nodes in the graph.

The distance between two nodes is defined as the number of edges between them.

You must return an array ‘ANSWER’ of size ‘N’, where ‘ANSWER[i]’ is the shortest distance between node ‘i’ and any node present in the cycle.

Note :

The graph is connected.
There is, at most, one edge between any pair of nodes.
There is exactly one cycle in the graph.

Example:

Input: N=7, edges=[[1, 2], [2, 3], [3, 4], [4, 1], [0, 1], [5, 2], [6, 5]]
Output: [1, 0, 0, 0, 0, 1, 2]
Explanation: The Nodes 1, 2, 3, and 4 form a cycle.
The distance between nodes 0 to 1 is 1.
The distance between nodes 1 to 1 is 0.
The distance between nodes 2 to 2 is 0.
The distance between nodes 3 to 3 is 0.
The distance between nodes 4 to 4 is 0.
The distance between nodes 5 to 2 is 1.
The distance between nodes 6 to 2 is 2.

Detailed explanation ( Input/output format, Notes, Images )

Input Format

First-line contains 'T', denoting the number of Test cases.
For each Test case:
The first line contains a single integer, ‘N,’ denoting the number of nodes in the graph.
The next ‘N’ lines contain two integers, ‘node0’ and ‘node1’, denoting an undirected edge between ‘node0’ and ‘node1’.

Output format:

Return the array ‘ANSWER’.

Note:-

You don't need to print anything. Just implement the given function.

For test case 1:
Input: N=7, edges=[[1, 2], [2, 3], [3, 4], [4, 1], [0, 1], [5, 2], [6, 5]]
Output: [1, 0, 0, 0, 0, 1, 2]
Explanation: The Nodes 1, 2, 3, and 4 form a cycle.
The distance between nodes 0 to 1 is 1.
The distance between nodes 1 to 1 is 0.
The distance between nodes 2 to 2 is 0.
The distance between nodes 3 to 3 is 0.
The distance between nodes 4 to 4 is 0.
The distance between nodes 5 to 2 is 1.
The distance between nodes 6 to 2 is 2.
For test case 2:
Input: N=3, edges=[[0, 1], [1, 2], [0, 2]]
Output: [0, 0, 0]
Explanation: The Nodes 0, 1, and 2 form a cycle.
The distance between nodes 0 to 0 is 0.
The distance between nodes 1 to 1 is 0.
The distance between nodes 2 to 2 is 0.