n = int(input())
l = [[] for i in range(n)]
retval=[10**10 for i in range(n)]



for i in range(n):
    _input = [int(j) - 1 for j in input().split(" ")]
    u = _input[0]
    k = _input[1] + 1
    node = sorted(_input[2::])
    if u in node:
        node.remove(u)
    l[u] = node

retval[0]=0
for step in range(n+1):
    for i ,d in enumerate(retval):
        if d==step:
            for node in l[i]:
                retval[node]=min(retval[node],step+1)

for i,d in enumerate(retval):
    if d==10**10:
        print(i+1,-1)
    else:
        print(i+1,d)
 n = int(input()) n int(input()) int input() input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] l = [[] for i in range(n)] l [[] for i in range(n)] 10**10 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 10**10 10 10 retval=[10**10 for i in range(n)] retval [10**10 for i in range(n)] for i in range(n):
    _input = [int(j) - 1 for j in input().split(" ")]
    u = _input[0]
    k = _input[1] + 1
    node = sorted(_input[2::])
    if u in node:
        node.remove(u)
    l[u] = node i range(n) range n int(j) - 1 for j in input().split(" ") for j in input().split(" ") j input().split(" ") ().split () input split " " for j in input().split(" ") int(j) - 1 int(j) int j 1 _input = [int(j) - 1 for j in input().split(" ")] _input [int(j) - 1 for j in input().split(" ")] u = _input[0] u _input[0] _input 0 k = _input[1] + 1 k _input[1] + 1 _input[1] _input 1 1 node = sorted(_input[2::]) node sorted(_input[2::]) sorted _input[2::] _input 2:: 2 if u in node:
        node.remove(u)
     u in node u node node.remove(u) node.remove node remove u l[u] = node l[u] l u node retval[0]=0 retval[0] retval 0 0 for step in range(n+1):
    for i ,d in enumerate(retval):
        if d==step:
            for node in l[i]:
                retval[node]=min(retval[node],step+1) step range(n+1) range n+1 n 1 for i ,d in enumerate(retval):
        if d==step:
            for node in l[i]:
                retval[node]=min(retval[node],step+1) i d enumerate(retval) enumerate retval if d==step:
            for node in l[i]:
                retval[node]=min(retval[node],step+1) d==step d step for node in l[i]:
                retval[node]=min(retval[node],step+1) node l[i] l i retval[node]=min(retval[node],step+1) retval[node] retval node min(retval[node],step+1) min retval[node] retval node step+1 step 1 for i,d in enumerate(retval):
    if d==10**10:
        print(i+1,-1)
    else:
        print(i+1,d) i d enumerate(retval) enumerate retval if d==10**10:
        print(i+1,-1)
    else:
        print(i+1,d) d==10**10 d 10**10 10 10 print(i+1,-1) print i+1 i 1 -1 print(i+1,d) print i+1 i 1 d n = int(input()) int(input()) n k = _input[1] + 1 _input[1] + 1 k l = [[] for i in range(n)] [[] for i in range(n)] l u = _input[0] _input[0] u node = sorted(_input[2::]) sorted(_input[2::]) node _input = [int(j) - 1 for j in input().split(" ")] [int(j) - 1 for j in input().split(" ")] _input retval=[10**10 for i in range(n)] [10**10 for i in range(n)] retval
n = int(input())
l = [[] for i in range(n)]
retval=[10**10 for i in range(n)]



for i in range(n):
    _input = [int(j) - 1 for j in input().split(" ")]
    u = _input[0]
    k = _input[1] + 1
    node = sorted(_input[2::])
    if u in node:
        node.remove(u)
    l[u] = node

retval[0]=0
for step in range(n+1):
    for i ,d in enumerate(retval):
        if d==step:
            for node in l[i]:
                retval[node]=min(retval[node],step+1)

for i,d in enumerate(retval):
    if d==10**10:
        print(i+1,-1)
    else:
        print(i+1,d)

