from sys import stdin
from collections import deque
n = int(stdin.readline())
M = [[0] * (n + 1) for _ in range(n + 1)]
d = [200] * (n + 1)
def bfs():
    d[1] = 0
    dq = deque()
    dq.append(1)
    while len(dq) > 0:
        u = dq.popleft()
        for v in range(1, n + 1):
            if M[u][v] == 0 or d[v] != 200: continue
            d[v] = d[u] + 1
            dq.append(v)
    for i in range(1, n + 1):
        print(i, (-1 if d[i] == 200 else d[i]))
for u in range(1, n + 1):
    U = [int(j) for j in stdin.readline().split()]
    for v in U[2:]:
        M[u][v] = 1
bfs() from sys import stdin from collections import deque n = int(stdin.readline()) n int(stdin.readline()) int stdin.readline() stdin.readline stdin readline [0] * (n + 1) for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) [0] * (n + 1) [0] 0 n + 1 n 1 M = [[0] * (n + 1) for _ in range(n + 1)] M [[0] * (n + 1) for _ in range(n + 1)] d = [200] * (n + 1) d [200] * (n + 1) [200] 200 n + 1 n 1 def bfs():
    d[1] = 0
    dq = deque()
    dq.append(1)
    while len(dq) > 0:
        u = dq.popleft()
        for v in range(1, n + 1):
            if M[u][v] == 0 or d[v] != 200: continue
            d[v] = d[u] + 1
            dq.append(v)
    for i in range(1, n + 1):
        print(i, (-1 if d[i] == 200 else d[i])) bfs d[1] = 0 d[1] d 1 0 dq = deque() dq deque() deque dq.append(1) dq.append dq append 1 while len(dq) > 0:
        u = dq.popleft()
        for v in range(1, n + 1):
            if M[u][v] == 0 or d[v] != 200: continue
            d[v] = d[u] + 1
            dq.append(v)
     len(dq) > 0 len(dq) len dq 0 u = dq.popleft() u dq.popleft() dq.popleft dq popleft for v in range(1, n + 1):
            if M[u][v] == 0 or d[v] != 200: continue
            d[v] = d[u] + 1
            dq.append(v)
     v range(1, n + 1) range 1 n + 1 n 1 if M[u][v] == 0 or d[v] != 200: continue
             M[u][v] == 0 or d[v] != 200 M[u][v] == 0 M[u][v] [u] M u v 0 d[v] != 200 d[v] d v 200 d[v] = d[u] + 1 d[v] d v d[u] + 1 d[u] d u 1 dq.append(v) dq.append dq append v for i in range(1, n + 1):
        print(i, (-1 if d[i] == 200 else d[i])) i range(1, n + 1) range 1 n + 1 n 1 print(i, (-1 if d[i] == 200 else d[i])) print i -1 if d[i] == 200 else d[i] d[i] == 200 d[i] d i 200 -1 d[i] d i for u in range(1, n + 1):
    U = [int(j) for j in stdin.readline().split()]
    for v in U[2:]:
        M[u][v] = 1 u range(1, n + 1) range 1 n + 1 n 1 int(j) for j in stdin.readline().split() for j in stdin.readline().split() j stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split for j in stdin.readline().split() int(j) int j U = [int(j) for j in stdin.readline().split()] U [int(j) for j in stdin.readline().split()] for v in U[2:]:
        M[u][v] = 1 v U[2:] U 2: 2 M[u][v] = 1 M[u][v] [u] M u v 1 bfs() bfs n = int(stdin.readline()) int(stdin.readline()) n M = [[0] * (n + 1) for _ in range(n + 1)] [[0] * (n + 1) for _ in range(n + 1)] M d = [200] * (n + 1) [200] * (n + 1) d def bfs():
    d[1] = 0
    dq = deque()
    dq.append(1)
    while len(dq) > 0:
        u = dq.popleft()
        for v in range(1, n + 1):
            if M[u][v] == 0 or d[v] != 200: continue
            d[v] = d[u] + 1
            dq.append(v)
    for i in range(1, n + 1):
        print(i, (-1 if d[i] == 200 else d[i])) def bfs():
    d[1] = 0
    dq = deque()
    dq.append(1)
    while len(dq) > 0:
        u = dq.popleft()
        for v in range(1, n + 1):
            if M[u][v] == 0 or d[v] != 200: continue
            d[v] = d[u] + 1
            dq.append(v)
    for i in range(1, n + 1):
        print(i, (-1 if d[i] == 200 else d[i])) bfs U = [int(j) for j in stdin.readline().split()] [int(j) for j in stdin.readline().split()] U
from sys import stdin
from collections import deque
n = int(stdin.readline())
M = [[0] * (n + 1) for _ in range(n + 1)]
d = [200] * (n + 1)
def bfs():
    d[1] = 0
    dq = deque()
    dq.append(1)
    while len(dq) > 0:
        u = dq.popleft()
        for v in range(1, n + 1):
            if M[u][v] == 0 or d[v] != 200: continue
            d[v] = d[u] + 1
            dq.append(v)
    for i in range(1, n + 1):
        print(i, (-1 if d[i] == 200 else d[i]))
for u in range(1, n + 1):
    U = [int(j) for j in stdin.readline().split()]
    for v in U[2:]:
        M[u][v] = 1
bfs()