n = int(input())

m = [[0 for _ in range(n)] for _ in range(n)]

for _ in range(n):
    tmp = [int(x) for x in input().split()]
    u = tmp[0]
    k = tmp[1]
    l = tmp[2:]
    for x in l:
        m[u-1][x-1] = 1

dl = [float('inf') for _  in range(n)]
dl[0] = 0

q = [0]

while q:
    t = q.pop()
    tl = m[t]
    for i,x in enumerate(tl):
        if x == 1:
            if dl[i] > dl[t] + 1:
                q.append(i)
                dl[i] = dl[t] + 1
            else:
                pass
        else:
            pass


for i,x in enumerate(dl):
    if x == float('inf'):
        print(i+1, -1)
    else:
        print(i+1, x)
 n = int(input()) n int(input()) int input() input [0 for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0 for _ in range(n)] m = [[0 for _ in range(n)] for _ in range(n)] m [[0 for _ in range(n)] for _ in range(n)] for _ in range(n):
    tmp = [int(x) for x in input().split()]
    u = tmp[0]
    k = tmp[1]
    l = tmp[2:]
    for x in l:
        m[u-1][x-1] = 1 _ range(n) range n int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x tmp = [int(x) for x in input().split()] tmp [int(x) for x in input().split()] u = tmp[0] u tmp[0] tmp 0 k = tmp[1] k tmp[1] tmp 1 l = tmp[2:] l tmp[2:] tmp 2: 2 for x in l:
        m[u-1][x-1] = 1 x l m[u-1][x-1] = 1 m[u-1][x-1] [u-1] m u-1 u 1 x-1 x 1 1 float('inf') for _  in range(n) for _  in range(n) _ range(n) range n for _  in range(n) float('inf') float 'inf' dl = [float('inf') for _  in range(n)] dl [float('inf') for _  in range(n)] dl[0] = 0 dl[0] dl 0 0 q = [0] q [0] 0 while q:
    t = q.pop()
    tl = m[t]
    for i,x in enumerate(tl):
        if x == 1:
            if dl[i] > dl[t] + 1:
                q.append(i)
                dl[i] = dl[t] + 1
            else:
                pass
        else:
            pass q t = q.pop() t q.pop() q.pop q pop tl = m[t] tl m[t] m t for i,x in enumerate(tl):
        if x == 1:
            if dl[i] > dl[t] + 1:
                q.append(i)
                dl[i] = dl[t] + 1
            else:
                pass
        else:
            pass i x enumerate(tl) enumerate tl if x == 1:
            if dl[i] > dl[t] + 1:
                q.append(i)
                dl[i] = dl[t] + 1
            else:
                pass
        else:
            pass x == 1 x 1 if dl[i] > dl[t] + 1:
                q.append(i)
                dl[i] = dl[t] + 1
            else:
                pass
         dl[i] > dl[t] + 1 dl[i] dl i dl[t] + 1 dl[t] dl t 1 q.append(i) q.append q append i dl[i] = dl[t] + 1 dl[i] dl i dl[t] + 1 dl[t] dl t 1 for i,x in enumerate(dl):
    if x == float('inf'):
        print(i+1, -1)
    else:
        print(i+1, x) i x enumerate(dl) enumerate dl if x == float('inf'):
        print(i+1, -1)
    else:
        print(i+1, x) x == float('inf') x float('inf') float 'inf' print(i+1, -1) print i+1 i 1 -1 print(i+1, x) print i+1 i 1 x n = int(input()) int(input()) n tmp = [int(x) for x in input().split()] [int(x) for x in input().split()] tmp k = tmp[1] tmp[1] k t = q.pop() q.pop() t tl = m[t] m[t] tl u = tmp[0] tmp[0] u m = [[0 for _ in range(n)] for _ in range(n)] [[0 for _ in range(n)] for _ in range(n)] m l = tmp[2:] tmp[2:] l q = [0] [0] q dl = [float('inf') for _  in range(n)] [float('inf') for _  in range(n)] dl
n = int(input())

m = [[0 for _ in range(n)] for _ in range(n)]

for _ in range(n):
    tmp = [int(x) for x in input().split()]
    u = tmp[0]
    k = tmp[1]
    l = tmp[2:]
    for x in l:
        m[u-1][x-1] = 1

dl = [float('inf') for _  in range(n)]
dl[0] = 0

q = [0]

while q:
    t = q.pop()
    tl = m[t]
    for i,x in enumerate(tl):
        if x == 1:
            if dl[i] > dl[t] + 1:
                q.append(i)
                dl[i] = dl[t] + 1
            else:
                pass
        else:
            pass


for i,x in enumerate(dl):
    if x == float('inf'):
        print(i+1, -1)
    else:
        print(i+1, x)

