n = input()

d = [-1 for i in xrange(n + 1)]
Q = []

color = ['WHITE' for i in xrange(n + 1)]

graph_map = [[0 for j in xrange(n + 1)] for i in xrange(n + 1)]

for i in xrange(1, n + 1):
    tmp = map(int, raw_input().split())
    for j in xrange(tmp[1]):
        graph_map[i][tmp[j + 2]] = 1

color[1] = 'GRAY'
d[1] = 0
Q.append(1)

while len(Q) != 0:
    u = Q.pop(0)
    for v in xrange(1, n + 1):
        if graph_map[u][v] == 1 and color[v] == 'WHITE':
            color[v] = 'GRAY'
            d[v] = d[u] + 1
            Q.append(v)
    color[u] = 'BLACK'

for i in xrange(1, n + 1):
    print "%d %d" % (i, d[i]) n = input() n input() input -1 for i in xrange(n + 1) for i in xrange(n + 1) i xrange(n + 1) xrange n + 1 n 1 for i in xrange(n + 1) -1 d = [-1 for i in xrange(n + 1)] d [-1 for i in xrange(n + 1)] Q = [] Q [] 'WHITE' for i in xrange(n + 1) for i in xrange(n + 1) i xrange(n + 1) xrange n + 1 n 1 for i in xrange(n + 1) 'WHITE' color = ['WHITE' for i in xrange(n + 1)] color ['WHITE' for i in xrange(n + 1)] [0 for j in xrange(n + 1)] for i in xrange(n + 1) for i in xrange(n + 1) i xrange(n + 1) xrange n + 1 n 1 for i in xrange(n + 1) [0 for j in xrange(n + 1)] graph_map = [[0 for j in xrange(n + 1)] for i in xrange(n + 1)] graph_map [[0 for j in xrange(n + 1)] for i in xrange(n + 1)] for i in xrange(1, n + 1):
    tmp = map(int, raw_input().split())
    for j in xrange(tmp[1]):
        graph_map[i][tmp[j + 2]] = 1 i xrange(1, n + 1) xrange 1 n + 1 n 1 tmp = map(int, raw_input().split()) tmp map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split for j in xrange(tmp[1]):
        graph_map[i][tmp[j + 2]] = 1 j xrange(tmp[1]) xrange tmp[1] tmp 1 graph_map[i][tmp[j + 2]] = 1 graph_map[i][tmp[j + 2]] [i] graph_map i tmp[j + 2] tmp j + 2 j 2 1 color[1] = 'GRAY' color[1] color 1 'GRAY' d[1] = 0 d[1] d 1 0 Q.append(1) Q.append Q append 1 while len(Q) != 0:
    u = Q.pop(0)
    for v in xrange(1, n + 1):
        if graph_map[u][v] == 1 and color[v] == 'WHITE':
            color[v] = 'GRAY'
            d[v] = d[u] + 1
            Q.append(v)
    color[u] = 'BLACK' len(Q) != 0 len(Q) len Q 0 u = Q.pop(0) u Q.pop(0) Q.pop Q pop 0 for v in xrange(1, n + 1):
        if graph_map[u][v] == 1 and color[v] == 'WHITE':
            color[v] = 'GRAY'
            d[v] = d[u] + 1
            Q.append(v)
     v xrange(1, n + 1) xrange 1 n + 1 n 1 if graph_map[u][v] == 1 and color[v] == 'WHITE':
            color[v] = 'GRAY'
            d[v] = d[u] + 1
            Q.append(v)
     graph_map[u][v] == 1 and color[v] == 'WHITE' graph_map[u][v] == 1 graph_map[u][v] [u] graph_map u v 1 color[v] == 'WHITE' color[v] color v 'WHITE' color[v] = 'GRAY' color[v] color v 'GRAY' d[v] = d[u] + 1 d[v] d v d[u] + 1 d[u] d u 1 Q.append(v) Q.append Q append v color[u] = 'BLACK' color[u] color u 'BLACK' for i in xrange(1, n + 1):
    print "%d %d" % (i, d[i]) i xrange(1, n + 1) xrange 1 n + 1 n 1 print "%d %d" % (i, d[i]) "%d %d" (i, d[i]) i d[i] d i Q = [] [] Q d = [-1 for i in xrange(n + 1)] [-1 for i in xrange(n + 1)] d tmp = map(int, raw_input().split()) map(int, raw_input().split()) tmp n = input() input() n color = ['WHITE' for i in xrange(n + 1)] ['WHITE' for i in xrange(n + 1)] color u = Q.pop(0) Q.pop(0) u graph_map = [[0 for j in xrange(n + 1)] for i in xrange(n + 1)] [[0 for j in xrange(n + 1)] for i in xrange(n + 1)] graph_map
n = input()

d = [-1 for i in xrange(n + 1)]
Q = []

color = ['WHITE' for i in xrange(n + 1)]

graph_map = [[0 for j in xrange(n + 1)] for i in xrange(n + 1)]

for i in xrange(1, n + 1):
    tmp = map(int, raw_input().split())
    for j in xrange(tmp[1]):
        graph_map[i][tmp[j + 2]] = 1

color[1] = 'GRAY'
d[1] = 0
Q.append(1)

while len(Q) != 0:
    u = Q.pop(0)
    for v in xrange(1, n + 1):
        if graph_map[u][v] == 1 and color[v] == 'WHITE':
            color[v] = 'GRAY'
            d[v] = d[u] + 1
            Q.append(v)
    color[u] = 'BLACK'

for i in xrange(1, n + 1):
    print "%d %d" % (i, d[i])