n = int(input())
G = [[] for i in range(n)] #G(i): 頂点iと隣接する頂点のlist
for i in range(n):
    a = [int(i) for i in input().split()]
    G[a[0]-1] = [i-1 for i in a[2:]]

d = [-1] * n
todo = [0]
d[0] = 0

while(todo != []):
    v = todo.pop(0)
    for i in G[v]:
        if d[i] == -1:
            d[i] = d[v]+1
            todo.append(i)

for i in range(n):
    print(i+1, d[i]) n = int(input()) n int(input()) int input() input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] G = [[] for i in range(n)] G [[] for i in range(n)] for i in range(n):
    a = [int(i) for i in input().split()]
    G[a[0]-1] = [i-1 for i in a[2:]] i range(n) range n int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a = [int(i) for i in input().split()] a [int(i) for i in input().split()] i-1 for i in a[2:] for i in a[2:] i a[2:] a 2: 2 for i in a[2:] i-1 i 1 G[a[0]-1] = [i-1 for i in a[2:]] G[a[0]-1] G a[0]-1 a[0] a 0 1 [i-1 for i in a[2:]] d = [-1] * n d [-1] * n [-1] -1 n todo = [0] todo [0] 0 d[0] = 0 d[0] d 0 0 while(todo != []):
    v = todo.pop(0)
    for i in G[v]:
        if d[i] == -1:
            d[i] = d[v]+1
            todo.append(i) todo != [] todo [] v = todo.pop(0) v todo.pop(0) todo.pop todo pop 0 for i in G[v]:
        if d[i] == -1:
            d[i] = d[v]+1
            todo.append(i) i G[v] G v if d[i] == -1:
            d[i] = d[v]+1
            todo.append(i) d[i] == -1 d[i] d i -1 d[i] = d[v]+1 d[i] d i d[v]+1 d[v] d v 1 todo.append(i) todo.append todo append i for i in range(n):
    print(i+1, d[i]) i range(n) range n print(i+1, d[i]) print i+1 i 1 d[i] d i n = int(input()) int(input()) n G = [[] for i in range(n)] [[] for i in range(n)] G a = [int(i) for i in input().split()] [int(i) for i in input().split()] a d = [-1] * n [-1] * n d todo = [0] [0] todo v = todo.pop(0) todo.pop(0) v
n = int(input())
G = [[] for i in range(n)] #G(i): 頂点iと隣接する頂点のlist
for i in range(n):
    a = [int(i) for i in input().split()]
    G[a[0]-1] = [i-1 for i in a[2:]]

d = [-1] * n
todo = [0]
d[0] = 0

while(todo != []):
    v = todo.pop(0)
    for i in G[v]:
        if d[i] == -1:
            d[i] = d[v]+1
            todo.append(i)

for i in range(n):
    print(i+1, d[i])
