# 28
# ALDS_11_C - 幅優先探索

from collections import deque

n = int(input())
u_l = []
k_l = []
v_l = []

for i in range(n):
    _v_l = []
    for j, _ in enumerate(input().split()):
        if j == 0:
            u_l.append(int(_))
        elif j == 1:
            k_l.append(int(_))
        else:
            _v_l.append(int(_))
    v_l.append(_v_l)
        
d_l = [-1]*n
d_l[0] = 0
s_dq = deque([1])
while len(s_dq) > 0:
    _s = s_dq.popleft()
    _s -= 1
    for i in range(k_l[_s]):
        _v = v_l[_s][i]
        if d_l[_v-1] == -1:
            s_dq.append(_v)
            d_l[_v-1] = d_l[_s] + 1

for _id, _d in zip(range(1,n+1), d_l):
    print(_id, _d)
 from collections import deque n = int(input()) n int(input()) int input() input u_l = [] u_l [] k_l = [] k_l [] v_l = [] v_l [] for i in range(n):
    _v_l = []
    for j, _ in enumerate(input().split()):
        if j == 0:
            u_l.append(int(_))
        elif j == 1:
            k_l.append(int(_))
        else:
            _v_l.append(int(_))
    v_l.append(_v_l)
         i range(n) range n _v_l = [] _v_l [] for j, _ in enumerate(input().split()):
        if j == 0:
            u_l.append(int(_))
        elif j == 1:
            k_l.append(int(_))
        else:
            _v_l.append(int(_))
     j _ enumerate(input().split()) enumerate input().split() ().split () input split if j == 0:
            u_l.append(int(_))
        elif j == 1:
            k_l.append(int(_))
        else:
            _v_l.append(int(_))
     j == 0 j 0 u_l.append(int(_)) u_l.append u_l append int(_) int _ elif j == 1:
            k_l.append(int(_))
         j == 1 j 1 k_l.append(int(_)) k_l.append k_l append int(_) int _ _v_l.append(int(_)) _v_l.append _v_l append int(_) int _ v_l.append(_v_l) v_l.append v_l append _v_l d_l = [-1]*n d_l [-1]*n [-1] -1 n d_l[0] = 0 d_l[0] d_l 0 0 s_dq = deque([1]) s_dq deque([1]) deque [1] 1 while len(s_dq) > 0:
    _s = s_dq.popleft()
    _s -= 1
    for i in range(k_l[_s]):
        _v = v_l[_s][i]
        if d_l[_v-1] == -1:
            s_dq.append(_v)
            d_l[_v-1] = d_l[_s] + 1 len(s_dq) > 0 len(s_dq) len s_dq 0 _s = s_dq.popleft() _s s_dq.popleft() s_dq.popleft s_dq popleft _s -= 1 _s 1 for i in range(k_l[_s]):
        _v = v_l[_s][i]
        if d_l[_v-1] == -1:
            s_dq.append(_v)
            d_l[_v-1] = d_l[_s] + 1 i range(k_l[_s]) range k_l[_s] k_l _s _v = v_l[_s][i] _v v_l[_s][i] [_s] v_l _s i if d_l[_v-1] == -1:
            s_dq.append(_v)
            d_l[_v-1] = d_l[_s] + 1 d_l[_v-1] == -1 d_l[_v-1] d_l _v-1 _v 1 -1 s_dq.append(_v) s_dq.append s_dq append _v d_l[_v-1] = d_l[_s] + 1 d_l[_v-1] d_l _v-1 _v 1 d_l[_s] + 1 d_l[_s] d_l _s 1 for _id, _d in zip(range(1,n+1), d_l):
    print(_id, _d) _id _d zip(range(1,n+1), d_l) zip range(1,n+1) range 1 n+1 n 1 d_l print(_id, _d) print _id _d d_l = [-1]*n [-1]*n d_l _s = s_dq.popleft() s_dq.popleft() _s u_l = [] [] u_l k_l = [] [] k_l _s -= 1 1 _s v_l = [] [] v_l _v = v_l[_s][i] v_l[_s][i] _v n = int(input()) int(input()) n s_dq = deque([1]) deque([1]) s_dq _v_l = [] [] _v_l
# 28
# ALDS_11_C - 幅優先探索

from collections import deque

n = int(input())
u_l = []
k_l = []
v_l = []

for i in range(n):
    _v_l = []
    for j, _ in enumerate(input().split()):
        if j == 0:
            u_l.append(int(_))
        elif j == 1:
            k_l.append(int(_))
        else:
            _v_l.append(int(_))
    v_l.append(_v_l)
        
d_l = [-1]*n
d_l[0] = 0
s_dq = deque([1])
while len(s_dq) > 0:
    _s = s_dq.popleft()
    _s -= 1
    for i in range(k_l[_s]):
        _v = v_l[_s][i]
        if d_l[_v-1] == -1:
            s_dq.append(_v)
            d_l[_v-1] = d_l[_s] + 1

for _id, _d in zip(range(1,n+1), d_l):
    print(_id, _d)

