import queue

N = int(input())
G = []
for _ in range(N):
    u, n, *K = map(int, input().split())
    G.append((u - 1, [k - 1 for k in K]))

Q = queue.Queue()
Q.put(G[0])
dist = [-1] * N
dist[0] = 0
while not Q.empty():
    U = Q.get()
    for u in U[1]:
        if dist[u] == -1:
            Q.put(G[u])
            dist[u] = dist[U[0]] + 1

for i, time in enumerate(dist):
    print(i + 1, time)
 import queue queue N = int(input()) N int(input()) int input() input G = [] G [] for _ in range(N):
    u, n, *K = map(int, input().split())
    G.append((u - 1, [k - 1 for k in K])) _ range(N) range N u, n, *K = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split n *K K k - 1 for k in K for k in K k K for k in K k - 1 k 1 G.append((u - 1, [k - 1 for k in K])) G.append G append (u - 1, [k - 1 for k in K]) u - 1 u 1 [k - 1 for k in K] Q = queue.Queue() Q queue.Queue() queue.Queue queue Queue Q.put(G[0]) Q.put Q put G[0] G 0 dist = [-1] * N dist [-1] * N [-1] -1 N dist[0] = 0 dist[0] dist 0 0 while not Q.empty():
    U = Q.get()
    for u in U[1]:
        if dist[u] == -1:
            Q.put(G[u])
            dist[u] = dist[U[0]] + 1 not Q.empty() Q.empty() Q.empty Q empty U = Q.get() U Q.get() Q.get Q get for u in U[1]:
        if dist[u] == -1:
            Q.put(G[u])
            dist[u] = dist[U[0]] + 1 u U[1] U 1 if dist[u] == -1:
            Q.put(G[u])
            dist[u] = dist[U[0]] + 1 dist[u] == -1 dist[u] dist u -1 Q.put(G[u]) Q.put Q put G[u] G u dist[u] = dist[U[0]] + 1 dist[u] dist u dist[U[0]] + 1 dist[U[0]] dist U[0] U 0 1 for i, time in enumerate(dist):
    print(i + 1, time) i time enumerate(dist) enumerate dist print(i + 1, time) print i + 1 i 1 time n, *K = map(int, input().split()) map(int, input().split()) n dist = [-1] * N [-1] * N dist U = Q.get() Q.get() U N = int(input()) int(input()) N u, n, *K = map(int, input().split()) map(int, input().split()) u Q = queue.Queue() queue.Queue() Q G = [] [] G
import queue

N = int(input())
G = []
for _ in range(N):
    u, n, *K = map(int, input().split())
    G.append((u - 1, [k - 1 for k in K]))

Q = queue.Queue()
Q.put(G[0])
dist = [-1] * N
dist[0] = 0
while not Q.empty():
    U = Q.get()
    for u in U[1]:
        if dist[u] == -1:
            Q.put(G[u])
            dist[u] = dist[U[0]] + 1

for i, time in enumerate(dist):
    print(i + 1, time)

