import sys

global status, d
status = {}
d=0

def bfs(keys, GRAPH, depth=0):
    global status
    if depth>10: quit

    buf =[]
    for e in keys:
        if status[e]==-1:
            status[e]=depth
            for e2 in GRAPH[e]:
                try:
                    if status[e2] == -1:
                        buf.append(e2)
                except:
                    pass
    if buf !=[]:
        bfs(buf, GRAPH, depth+1)
    return

n = int(raw_input())
x = {}
for i in range(n):
    seq = map(int,raw_input().split())
    key = seq[0]
    if key != 0:
        x[key] = seq[2:]
    else:
        x[key]=[]
    status[key] = -1

for e in x.keys():
    if e == 1:
        bfs([e], x)

for e in x.keys():
    print e, status[e] import sys sys global status, d status = {} status {} d=0 d 0 def bfs(keys, GRAPH, depth=0):
    global status
    if depth>10: quit

    buf =[]
    for e in keys:
        if status[e]==-1:
            status[e]=depth
            for e2 in GRAPH[e]:
                try:
                    if status[e2] == -1:
                        buf.append(e2)
                except:
                    pass
    if buf !=[]:
        bfs(buf, GRAPH, depth+1)
    return bfs global status if depth>10: quit

     depth>10 depth 10 buf =[] buf [] for e in keys:
        if status[e]==-1:
            status[e]=depth
            for e2 in GRAPH[e]:
                try:
                    if status[e2] == -1:
                        buf.append(e2)
                except:
                    pass
     e keys if status[e]==-1:
            status[e]=depth
            for e2 in GRAPH[e]:
                try:
                    if status[e2] == -1:
                        buf.append(e2)
                except:
                    pass
     status[e]==-1 status[e] status e -1 status[e]=depth status[e] status e depth for e2 in GRAPH[e]:
                try:
                    if status[e2] == -1:
                        buf.append(e2)
                except:
                    pass
     e2 GRAPH[e] GRAPH e try:
                    if status[e2] == -1:
                        buf.append(e2)
                except:
                    pass
     except:
                    pass
     if status[e2] == -1:
                        buf.append(e2)
                 status[e2] == -1 status[e2] status e2 -1 buf.append(e2) buf.append buf append e2 if buf !=[]:
        bfs(buf, GRAPH, depth+1)
     buf !=[] buf [] bfs(buf, GRAPH, depth+1) bfs buf GRAPH depth+1 depth 1 return keys keys GRAPH GRAPH depth=0 depth 0 n = int(raw_input()) n int(raw_input()) int raw_input() raw_input x = {} x {} for i in range(n):
    seq = map(int,raw_input().split())
    key = seq[0]
    if key != 0:
        x[key] = seq[2:]
    else:
        x[key]=[]
    status[key] = -1 i range(n) range n seq = map(int,raw_input().split()) seq map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split key = seq[0] key seq[0] seq 0 if key != 0:
        x[key] = seq[2:]
    else:
        x[key]=[]
     key != 0 key 0 x[key] = seq[2:] x[key] x key seq[2:] seq 2: 2 x[key]=[] x[key] x key [] status[key] = -1 status[key] status key -1 for e in x.keys():
    if e == 1:
        bfs([e], x) e x.keys() x.keys x keys if e == 1:
        bfs([e], x) e == 1 e 1 bfs([e], x) bfs [e] e x for e in x.keys():
    print e, status[e] e x.keys() x.keys x keys print e status[e] status e seq = map(int,raw_input().split()) map(int,raw_input().split()) seq def bfs(keys, GRAPH, depth=0):
    global status
    if depth>10: quit

    buf =[]
    for e in keys:
        if status[e]==-1:
            status[e]=depth
            for e2 in GRAPH[e]:
                try:
                    if status[e2] == -1:
                        buf.append(e2)
                except:
                    pass
    if buf !=[]:
        bfs(buf, GRAPH, depth+1)
    return def bfs(keys, GRAPH, depth=0):
    global status
    if depth>10: quit

    buf =[]
    for e in keys:
        if status[e]==-1:
            status[e]=depth
            for e2 in GRAPH[e]:
                try:
                    if status[e2] == -1:
                        buf.append(e2)
                except:
                    pass
    if buf !=[]:
        bfs(buf, GRAPH, depth+1)
    return bfs d=0 0 d x = {} {} x key = seq[0] seq[0] key n = int(raw_input()) int(raw_input()) n status = {} {} status global status, d
import sys

global status, d
status = {}
d=0

def bfs(keys, GRAPH, depth=0):
    global status
    if depth>10: quit

    buf =[]
    for e in keys:
        if status[e]==-1:
            status[e]=depth
            for e2 in GRAPH[e]:
                try:
                    if status[e2] == -1:
                        buf.append(e2)
                except:
                    pass
    if buf !=[]:
        bfs(buf, GRAPH, depth+1)
    return

n = int(raw_input())
x = {}
for i in range(n):
    seq = map(int,raw_input().split())
    key = seq[0]
    if key != 0:
        x[key] = seq[2:]
    else:
        x[key]=[]
    status[key] = -1

for e in x.keys():
    if e == 1:
        bfs([e], x)

for e in x.keys():
    print e, status[e]