n = int(input())
graph = [[0 for i in range(n)] for j in range(n)]
d = [0] * n
f = [0] * n
queue = [0]


for i in range(n):
   a = list(map(int, input().split()))
   for j in range(0, a[1], 1):
       graph[a[0] - 1][a[2 + j] - 1] = 1

f[0] = 1
while len(queue) != 0:
    i = queue.pop(0)
    for j in range(n):
        if (graph[i][j] == 1) & (f[j] == 0):
            queue.append(j)
            f[j] = 1
            d[j] = d[i] + 1

[print(i+1, d[i] if (i == 0) | (d[i] != 0) else -1) for i in range(n)] n = int(input()) n int(input()) int input() input [0 for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [0 for i in range(n)] graph = [[0 for i in range(n)] for j in range(n)] graph [[0 for i in range(n)] for j in range(n)] d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n queue = [0] queue [0] 0 for i in range(n):
   a = list(map(int, input().split()))
   for j in range(0, a[1], 1):
       graph[a[0] - 1][a[2 + j] - 1] = 1 i range(n) range n a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for j in range(0, a[1], 1):
       graph[a[0] - 1][a[2 + j] - 1] = 1 j range(0, a[1], 1) range 0 a[1] a 1 1 graph[a[0] - 1][a[2 + j] - 1] = 1 graph[a[0] - 1][a[2 + j] - 1] [a[0] - 1] graph a[0] - 1 a[0] a 0 1 a[2 + j] - 1 a[2 + j] a 2 + j 2 j 1 1 f[0] = 1 f[0] f 0 1 while len(queue) != 0:
    i = queue.pop(0)
    for j in range(n):
        if (graph[i][j] == 1) & (f[j] == 0):
            queue.append(j)
            f[j] = 1
            d[j] = d[i] + 1 len(queue) != 0 len(queue) len queue 0 i = queue.pop(0) i queue.pop(0) queue.pop queue pop 0 for j in range(n):
        if (graph[i][j] == 1) & (f[j] == 0):
            queue.append(j)
            f[j] = 1
            d[j] = d[i] + 1 j range(n) range n if (graph[i][j] == 1) & (f[j] == 0):
            queue.append(j)
            f[j] = 1
            d[j] = d[i] + 1 (graph[i][j] == 1) & (f[j] == 0) graph[i][j] == 1 graph[i][j] [i] graph i j 1 f[j] == 0 f[j] f j 0 queue.append(j) queue.append queue append j f[j] = 1 f[j] f j 1 d[j] = d[i] + 1 d[j] d j d[i] + 1 d[i] d i 1 print(i+1, d[i] if (i == 0) | (d[i] != 0) else -1) for i in range(n) for i in range(n) i range(n) range n for i in range(n) print(i+1, d[i] if (i == 0) | (d[i] != 0) else -1) print i+1 i 1 d[i] if (i == 0) | (d[i] != 0) else -1 (i == 0) | (d[i] != 0) i == 0 i 0 d[i] != 0 d[i] d i 0 d[i] d i -1 [print(i+1, d[i] if (i == 0) | (d[i] != 0) else -1) for i in range(n)] a = list(map(int, input().split())) list(map(int, input().split())) a graph = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] graph d = [0] * n [0] * n d i = queue.pop(0) queue.pop(0) i queue = [0] [0] queue f = [0] * n [0] * n f n = int(input()) int(input()) n
n = int(input())
graph = [[0 for i in range(n)] for j in range(n)]
d = [0] * n
f = [0] * n
queue = [0]


for i in range(n):
   a = list(map(int, input().split()))
   for j in range(0, a[1], 1):
       graph[a[0] - 1][a[2 + j] - 1] = 1

f[0] = 1
while len(queue) != 0:
    i = queue.pop(0)
    for j in range(n):
        if (graph[i][j] == 1) & (f[j] == 0):
            queue.append(j)
            f[j] = 1
            d[j] = d[i] + 1

[print(i+1, d[i] if (i == 0) | (d[i] != 0) else -1) for i in range(n)]
