n = int(input())
al = [list(map(lambda x: int(x) - 1, input().split()))[2:] for _ in range(n)]
queue = [0]
d = [-1] * n
d[0] = 0
while len(queue) > 0:
    u = queue.pop(0)
    for v in al[u]:
        if d[v] == -1:
            d[v] = d[u] + 1
            queue.append(v)
for i, x in enumerate(d):
    print('{} {}'.format(i + 1, x))

 n = int(input()) n int(input()) int input() input list(map(lambda x: int(x) - 1, input().split()))[2:] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) list(map(lambda x: int(x) - 1, input().split()))[2:] (map(lambda x: int(x) - 1, input().split())) list map(lambda x: int(x) - 1, input().split()) map lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x input().split() ().split () input split 2: 2 al = [list(map(lambda x: int(x) - 1, input().split()))[2:] for _ in range(n)] al [list(map(lambda x: int(x) - 1, input().split()))[2:] for _ in range(n)] queue = [0] queue [0] 0 d = [-1] * n d [-1] * n [-1] -1 n d[0] = 0 d[0] d 0 0 while len(queue) > 0:
    u = queue.pop(0)
    for v in al[u]:
        if d[v] == -1:
            d[v] = d[u] + 1
            queue.append(v) len(queue) > 0 len(queue) len queue 0 u = queue.pop(0) u queue.pop(0) queue.pop queue pop 0 for v in al[u]:
        if d[v] == -1:
            d[v] = d[u] + 1
            queue.append(v) v al[u] al u if d[v] == -1:
            d[v] = d[u] + 1
            queue.append(v) d[v] == -1 d[v] d v -1 d[v] = d[u] + 1 d[v] d v d[u] + 1 d[u] d u 1 queue.append(v) queue.append queue append v for i, x in enumerate(d):
    print('{} {}'.format(i + 1, x)) i x enumerate(d) enumerate d print('{} {}'.format(i + 1, x)) print '{} {}'.format(i + 1, x) '{} {}'.format '{} {}' format i + 1 i 1 x al = [list(map(lambda x: int(x) - 1, input().split()))[2:] for _ in range(n)] [list(map(lambda x: int(x) - 1, input().split()))[2:] for _ in range(n)] al queue = [0] [0] queue n = int(input()) int(input()) n d = [-1] * n [-1] * n d u = queue.pop(0) queue.pop(0) u
n = int(input())
al = [list(map(lambda x: int(x) - 1, input().split()))[2:] for _ in range(n)]
queue = [0]
d = [-1] * n
d[0] = 0
while len(queue) > 0:
    u = queue.pop(0)
    for v in al[u]:
        if d[v] == -1:
            d[v] = d[u] + 1
            queue.append(v)
for i, x in enumerate(d):
    print('{} {}'.format(i + 1, x))


