class Node(object):
    def __init__(self, V):
        self.V = V
        self.d = -1 
  
n = int(input())
nodes = [0] * 101
for i in range(n):
    data = input().split()
    V = list(map(int, data[2:]))
    V.sort(reverse = True)
    nodes[int(data[0])] = Node(V)
  
l = [1,]
l_old = []
cnt = 0

while len(l) > 0:
    l_old = l
    l = []
    for i in l_old:
        if nodes[i].d == -1:
            nodes[i].d = cnt
            V = nodes[i].V
            for j in V:
                if not j in l:
                    if nodes[j].d == -1:
                        l.append(j)
    cnt += 1
for i in range(1, n+1):
    if not isinstance(nodes[i], int):
        print(i, nodes[i].d) class Node(object):
    def __init__(self, V):
        self.V = V
        self.d = -1 
   Node def __init__(self, V):
        self.V = V
        self.d = -1 
   __init__ self.V = V self.V self V V self.d = -1 self.d self d -1 self self V V object n = int(input()) n int(input()) int input() input nodes = [0] * 101 nodes [0] * 101 [0] 0 101 for i in range(n):
    data = input().split()
    V = list(map(int, data[2:]))
    V.sort(reverse = True)
    nodes[int(data[0])] = Node(V)
   i range(n) range n data = input().split() data input().split() ().split () input split V = list(map(int, data[2:])) V list(map(int, data[2:])) list map(int, data[2:]) map int data[2:] data 2: 2 V.sort(reverse = True) V.sort V sort reverse = True reverse True nodes[int(data[0])] = Node(V) nodes[int(data[0])] nodes int(data[0]) int data[0] data 0 Node(V) Node V l = [1,] l [1,] 1 l_old = [] l_old [] cnt = 0 cnt 0 while len(l) > 0:
    l_old = l
    l = []
    for i in l_old:
        if nodes[i].d == -1:
            nodes[i].d = cnt
            V = nodes[i].V
            for j in V:
                if not j in l:
                    if nodes[j].d == -1:
                        l.append(j)
    cnt += 1 len(l) > 0 len(l) len l 0 l_old = l l_old l l = [] l [] for i in l_old:
        if nodes[i].d == -1:
            nodes[i].d = cnt
            V = nodes[i].V
            for j in V:
                if not j in l:
                    if nodes[j].d == -1:
                        l.append(j)
     i l_old if nodes[i].d == -1:
            nodes[i].d = cnt
            V = nodes[i].V
            for j in V:
                if not j in l:
                    if nodes[j].d == -1:
                        l.append(j)
     nodes[i].d == -1 nodes[i].d [i] nodes i d -1 nodes[i].d = cnt nodes[i].d [i] nodes i d cnt V = nodes[i].V V nodes[i].V [i] nodes i V for j in V:
                if not j in l:
                    if nodes[j].d == -1:
                        l.append(j)
     j V if not j in l:
                    if nodes[j].d == -1:
                        l.append(j)
     not j in l j in l j l if nodes[j].d == -1:
                        l.append(j)
     nodes[j].d == -1 nodes[j].d [j] nodes j d -1 l.append(j) l.append l append j cnt += 1 cnt 1 for i in range(1, n+1):
    if not isinstance(nodes[i], int):
        print(i, nodes[i].d) i range(1, n+1) range 1 n+1 n 1 if not isinstance(nodes[i], int):
        print(i, nodes[i].d) not isinstance(nodes[i], int) isinstance(nodes[i], int) isinstance nodes[i] nodes i int print(i, nodes[i].d) print i nodes[i].d [i] nodes i d n = int(input()) int(input()) n cnt = 0 0 cnt nodes = [0] * 101 [0] * 101 nodes data = input().split() input().split() data l_old = l l l_old l = [1,] [1,] l l = [] [] l V = nodes[i].V nodes[i].V V l_old = [] [] l_old V = list(map(int, data[2:])) list(map(int, data[2:])) V class Node(object):
    def __init__(self, V):
        self.V = V
        self.d = -1 
   class Node(object):
    def __init__(self, V):
        self.V = V
        self.d = -1 
   Node cnt += 1 1 cnt
class Node(object):
    def __init__(self, V):
        self.V = V
        self.d = -1 
  
n = int(input())
nodes = [0] * 101
for i in range(n):
    data = input().split()
    V = list(map(int, data[2:]))
    V.sort(reverse = True)
    nodes[int(data[0])] = Node(V)
  
l = [1,]
l_old = []
cnt = 0

while len(l) > 0:
    l_old = l
    l = []
    for i in l_old:
        if nodes[i].d == -1:
            nodes[i].d = cnt
            V = nodes[i].V
            for j in V:
                if not j in l:
                    if nodes[j].d == -1:
                        l.append(j)
    cnt += 1
for i in range(1, n+1):
    if not isinstance(nodes[i], int):
        print(i, nodes[i].d)