#coding:utf-8
n = int(input())
Q = [1]
M = [[False for i in range(n)] for j in range(n)]
dataList = []
for i in range(n):
    data = list(map(int,input().split()))
    dataList.append(data)
    for j in range(data[1]):
        v = data[j+2] - 1
        M[i][v] = True
color = ["white" for i in range(n)]
d = [-1 for i in range(n)]
d[0] = 0
while Q != []:
    u = Q.pop(0) - 1
    color[u] = "gray"
    data = dataList[u]
    for i in range(data[1]):
        v = data[i+2] - 1
        if M[u][v] == True and color[v] == "white":
            color[v] = "gray"
            d[v] = d[u] + 1
            Q.append(v+1)
    color[u] = "black"

for i,j in enumerate(d,1):
    print(i,j)
     n = int(input()) n int(input()) int input() input Q = [1] Q [1] 1 [False 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) [False for i in range(n)] M = [[False for i in range(n)] for j in range(n)] M [[False for i in range(n)] for j in range(n)] dataList = [] dataList [] for i in range(n):
    data = list(map(int,input().split()))
    dataList.append(data)
    for j in range(data[1]):
        v = data[j+2] - 1
        M[i][v] = True i range(n) range n data = list(map(int,input().split())) data list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split dataList.append(data) dataList.append dataList append data for j in range(data[1]):
        v = data[j+2] - 1
        M[i][v] = True j range(data[1]) range data[1] data 1 v = data[j+2] - 1 v data[j+2] - 1 data[j+2] data j+2 j 2 1 M[i][v] = True M[i][v] [i] M i v True "white" for i in range(n) for i in range(n) i range(n) range n for i in range(n) "white" color = ["white" for i in range(n)] color ["white" for i in range(n)] -1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) -1 d = [-1 for i in range(n)] d [-1 for i in range(n)] d[0] = 0 d[0] d 0 0 while Q != []:
    u = Q.pop(0) - 1
    color[u] = "gray"
    data = dataList[u]
    for i in range(data[1]):
        v = data[i+2] - 1
        if M[u][v] == True and color[v] == "white":
            color[v] = "gray"
            d[v] = d[u] + 1
            Q.append(v+1)
    color[u] = "black" Q != [] Q [] u = Q.pop(0) - 1 u Q.pop(0) - 1 Q.pop(0) Q.pop Q pop 0 1 color[u] = "gray" color[u] color u "gray" data = dataList[u] data dataList[u] dataList u for i in range(data[1]):
        v = data[i+2] - 1
        if M[u][v] == True and color[v] == "white":
            color[v] = "gray"
            d[v] = d[u] + 1
            Q.append(v+1)
     i range(data[1]) range data[1] data 1 v = data[i+2] - 1 v data[i+2] - 1 data[i+2] data i+2 i 2 1 if M[u][v] == True and color[v] == "white":
            color[v] = "gray"
            d[v] = d[u] + 1
            Q.append(v+1)
     M[u][v] == True and color[v] == "white" M[u][v] == True M[u][v] [u] M u v True color[v] == "white" color[v] color v "white" color[v] = "gray" color[v] color v "gray" d[v] = d[u] + 1 d[v] d v d[u] + 1 d[u] d u 1 Q.append(v+1) Q.append Q append v+1 v 1 color[u] = "black" color[u] color u "black" for i,j in enumerate(d,1):
    print(i,j)
     i j enumerate(d,1) enumerate d 1 print(i,j) print i j u = Q.pop(0) - 1 Q.pop(0) - 1 u M = [[False for i in range(n)] for j in range(n)] [[False for i in range(n)] for j in range(n)] M data = list(map(int,input().split())) list(map(int,input().split())) data v = data[j+2] - 1 data[j+2] - 1 v color = ["white" for i in range(n)] ["white" for i in range(n)] color v = data[i+2] - 1 data[i+2] - 1 v data = dataList[u] dataList[u] data dataList = [] [] dataList Q = [1] [1] Q n = int(input()) int(input()) n d = [-1 for i in range(n)] [-1 for i in range(n)] d
#coding:utf-8
n = int(input())
Q = [1]
M = [[False for i in range(n)] for j in range(n)]
dataList = []
for i in range(n):
    data = list(map(int,input().split()))
    dataList.append(data)
    for j in range(data[1]):
        v = data[j+2] - 1
        M[i][v] = True
color = ["white" for i in range(n)]
d = [-1 for i in range(n)]
d[0] = 0
while Q != []:
    u = Q.pop(0) - 1
    color[u] = "gray"
    data = dataList[u]
    for i in range(data[1]):
        v = data[i+2] - 1
        if M[u][v] == True and color[v] == "white":
            color[v] = "gray"
            d[v] = d[u] + 1
            Q.append(v+1)
    color[u] = "black"

for i,j in enumerate(d,1):
    print(i,j)
    
