import queue
n = int(input())

g = {}
for i in range(n):
    x = list(map(int, input().split()))
    g[x[0]] = [x[2:], 'w', x[0], None]

q = queue.Queue()
node = g[1]
node[-1] = 0
node[1] = 'g'
q.put(node)

while not q.empty():
    node  = q.get()
    d = node[-1] + 1
    for i in node[0]:
        ch = g[i]
        if ch[1] == 'w':
            ch[-1] = d
            ch[1] = 'g'
            q.put(ch)

for i in range(n):
    node = g[i+1]
    if node[-1] == None:
        d = -1
    else:
        d = node[-1]
    print("{} {}".format(i+1, d)) import queue queue n = int(input()) n int(input()) int input() input g = {} g {} for i in range(n):
    x = list(map(int, input().split()))
    g[x[0]] = [x[2:], 'w', x[0], None] i range(n) range n x = list(map(int, input().split())) x list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split g[x[0]] = [x[2:], 'w', x[0], None] g[x[0]] g x[0] x 0 [x[2:], 'w', x[0], None] x[2:] x 2: 2 'w' x[0] x 0 None q = queue.Queue() q queue.Queue() queue.Queue queue Queue node = g[1] node g[1] g 1 node[-1] = 0 node[-1] node -1 0 node[1] = 'g' node[1] node 1 'g' q.put(node) q.put q put node while not q.empty():
    node  = q.get()
    d = node[-1] + 1
    for i in node[0]:
        ch = g[i]
        if ch[1] == 'w':
            ch[-1] = d
            ch[1] = 'g'
            q.put(ch) not q.empty() q.empty() q.empty q empty node  = q.get() node q.get() q.get q get d = node[-1] + 1 d node[-1] + 1 node[-1] node -1 1 for i in node[0]:
        ch = g[i]
        if ch[1] == 'w':
            ch[-1] = d
            ch[1] = 'g'
            q.put(ch) i node[0] node 0 ch = g[i] ch g[i] g i if ch[1] == 'w':
            ch[-1] = d
            ch[1] = 'g'
            q.put(ch) ch[1] == 'w' ch[1] ch 1 'w' ch[-1] = d ch[-1] ch -1 d ch[1] = 'g' ch[1] ch 1 'g' q.put(ch) q.put q put ch for i in range(n):
    node = g[i+1]
    if node[-1] == None:
        d = -1
    else:
        d = node[-1]
    print("{} {}".format(i+1, d)) i range(n) range n node = g[i+1] node g[i+1] g i+1 i 1 if node[-1] == None:
        d = -1
    else:
        d = node[-1]
     node[-1] == None node[-1] node -1 None d = -1 d -1 d = node[-1] d node[-1] node -1 print("{} {}".format(i+1, d)) print "{} {}".format(i+1, d) "{} {}".format "{} {}" format i+1 i 1 d d = node[-1] node[-1] d node  = q.get() q.get() node q = queue.Queue() queue.Queue() q node = g[1] g[1] node g = {} {} g x = list(map(int, input().split())) list(map(int, input().split())) x ch = g[i] g[i] ch node = g[i+1] g[i+1] node d = node[-1] + 1 node[-1] + 1 d n = int(input()) int(input()) n d = -1 -1 d
import queue
n = int(input())

g = {}
for i in range(n):
    x = list(map(int, input().split()))
    g[x[0]] = [x[2:], 'w', x[0], None]

q = queue.Queue()
node = g[1]
node[-1] = 0
node[1] = 'g'
q.put(node)

while not q.empty():
    node  = q.get()
    d = node[-1] + 1
    for i in node[0]:
        ch = g[i]
        if ch[1] == 'w':
            ch[-1] = d
            ch[1] = 'g'
            q.put(ch)

for i in range(n):
    node = g[i+1]
    if node[-1] == None:
        d = -1
    else:
        d = node[-1]
    print("{} {}".format(i+1, d))