#D6749. Breadth First Search

    ID: 5609 Type: Default 1000ms 134MiB

Breadth First Search

Write a program which reads an directed graph G=(V,E)G = (V, E), and finds the shortest distance from vertex 11 to each vertex (the number of edges in the shortest path). Vertices are identified by IDs 1,2,...n1, 2, ... n.

Constraints

  • 1n1001 \leq n \leq 100

Input

In the first line, an integer nn denoting the number of vertices, is given. In the next nn lines, adjacent lists of vertex uu are given in the following format:

uu kk v1v_1 v2v_2 ... vkv_k

uu is ID of the vertex and kk denotes its degree.viv_i are IDs of vertices adjacent to uu.

Output

For each vertex uu, print idid and dd in a line. idid is ID of vertex uu and dd is the distance from vertex 11 to vertex uu. If there are no path from vertex 11 to vertex uu, print -1 as the shortest distance. Print in order of IDs.

Example

Input

4 1 2 2 4 2 1 4 3 0 4 1 3

Output

1 0 2 1 3 2 4 1

inputFormat

Input

In the first line, an integer nn denoting the number of vertices, is given. In the next nn lines, adjacent lists of vertex uu are given in the following format:

uu kk v1v_1 v2v_2 ... vkv_k

uu is ID of the vertex and kk denotes its degree.viv_i are IDs of vertices adjacent to uu.

outputFormat

Output

For each vertex uu, print idid and dd in a line. idid is ID of vertex uu and dd is the distance from vertex 11 to vertex uu. If there are no path from vertex 11 to vertex uu, print -1 as the shortest distance. Print in order of IDs.

Example

Input

4 1 2 2 4 2 1 4 3 0 4 1 3

Output

1 0 2 1 3 2 4 1

样例

4
1 2 2 4
2 1 4
3 0
4 1 3
1 0

2 1 3 2 4 1

</p>