n = int(input())
graph = {}
d = [-1] * (n+1)
for i in range(n):
    t = list(map(int, input().split()))
    v = t[0]
    k = t[1]
    graph[v] = [t[i+2] for i in range(k)]

from queue import Queue

def bfs(s):
    d[s] = 0
    q=Queue()
    q.put(s)
    while not q.empty():
        v=q.get()
        for child in graph[v]:
            if d[child] != -1: continue
            d[child] = d[v] + 1
            q.put(child)
bfs(1)
for i in range(1, n+1):print(i,d[i]) n = int(input()) n int(input()) int input() input graph = {} graph {} d = [-1] * (n+1) d [-1] * (n+1) [-1] -1 n+1 n 1 for i in range(n):
    t = list(map(int, input().split()))
    v = t[0]
    k = t[1]
    graph[v] = [t[i+2] for i in range(k)] i range(n) range n t = list(map(int, input().split())) t list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split v = t[0] v t[0] t 0 k = t[1] k t[1] t 1 t[i+2] for i in range(k) for i in range(k) i range(k) range k for i in range(k) t[i+2] t i+2 i 2 graph[v] = [t[i+2] for i in range(k)] graph[v] graph v [t[i+2] for i in range(k)] from queue import Queue def bfs(s):
    d[s] = 0
    q=Queue()
    q.put(s)
    while not q.empty():
        v=q.get()
        for child in graph[v]:
            if d[child] != -1: continue
            d[child] = d[v] + 1
            q.put(child) bfs d[s] = 0 d[s] d s 0 q=Queue() q Queue() Queue q.put(s) q.put q put s while not q.empty():
        v=q.get()
        for child in graph[v]:
            if d[child] != -1: continue
            d[child] = d[v] + 1
            q.put(child) not q.empty() q.empty() q.empty q empty v=q.get() v q.get() q.get q get for child in graph[v]:
            if d[child] != -1: continue
            d[child] = d[v] + 1
            q.put(child) child graph[v] graph v if d[child] != -1: continue
             d[child] != -1 d[child] d child -1 d[child] = d[v] + 1 d[child] d child d[v] + 1 d[v] d v 1 q.put(child) q.put q put child s s bfs(1) bfs 1 for i in range(1, n+1):print(i,d[i]) i range(1, n+1) range 1 n+1 n 1 def bfs(s):
    d[s] = 0
    q=Queue()
    q.put(s)
    while not q.empty():
        v=q.get()
        for child in graph[v]:
            if d[child] != -1: continue
            d[child] = d[v] + 1
            q.put(child) def bfs(s):
    d[s] = 0
    q=Queue()
    q.put(s)
    while not q.empty():
        v=q.get()
        for child in graph[v]:
            if d[child] != -1: continue
            d[child] = d[v] + 1
            q.put(child) bfs v = t[0] t[0] v d = [-1] * (n+1) [-1] * (n+1) d k = t[1] t[1] k graph = {} {} graph t = list(map(int, input().split())) list(map(int, input().split())) t n = int(input()) int(input()) n
n = int(input())
graph = {}
d = [-1] * (n+1)
for i in range(n):
    t = list(map(int, input().split()))
    v = t[0]
    k = t[1]
    graph[v] = [t[i+2] for i in range(k)]

from queue import Queue

def bfs(s):
    d[s] = 0
    q=Queue()
    q.put(s)
    while not q.empty():
        v=q.get()
        for child in graph[v]:
            if d[child] != -1: continue
            d[child] = d[v] + 1
            q.put(child)
bfs(1)
for i in range(1, n+1):print(i,d[i])