n = int(raw_input())



graph = [[] for i in range(n)]
for i in range(n):
    entry = map(int,raw_input().strip().split(' '))
    u = entry[0]-1
    for v in entry[2:]:
        v -= 1
        graph[u].append(v)

d = [-1 for i in range(n)]
d[0] = 0
t = 1
q = []
q.append(0)
while len(q) > 0:
    u = q[0]
    for v in graph[u]:
        if d[v] == -1:
            q.append(v)
            d[v] = d[u]+1
    del q[0]

for i in range(n):
    print i+1,d[i] n = int(raw_input()) n int(raw_input()) int raw_input() raw_input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] graph = [[] for i in range(n)] graph [[] for i in range(n)] for i in range(n):
    entry = map(int,raw_input().strip().split(' '))
    u = entry[0]-1
    for v in entry[2:]:
        v -= 1
        graph[u].append(v) i range(n) range n entry = map(int,raw_input().strip().split(' ')) entry map(int,raw_input().strip().split(' ')) map int raw_input().strip().split(' ') ().strip().split ().strip() ().strip () raw_input strip split ' ' u = entry[0]-1 u entry[0]-1 entry[0] entry 0 1 for v in entry[2:]:
        v -= 1
        graph[u].append(v) v entry[2:] entry 2: 2 v -= 1 v 1 graph[u].append(v) [u].append [u] graph u append v -1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) -1 d = [-1 for i in range(n)] d [-1 for i in range(n)] d[0] = 0 d[0] d 0 0 t = 1 t 1 q = [] q [] q.append(0) q.append q append 0 while len(q) > 0:
    u = q[0]
    for v in graph[u]:
        if d[v] == -1:
            q.append(v)
            d[v] = d[u]+1
    del q[0] len(q) > 0 len(q) len q 0 u = q[0] u q[0] q 0 for v in graph[u]:
        if d[v] == -1:
            q.append(v)
            d[v] = d[u]+1
     v graph[u] graph u if d[v] == -1:
            q.append(v)
            d[v] = d[u]+1
     d[v] == -1 d[v] d v -1 q.append(v) q.append q append v d[v] = d[u]+1 d[v] d v d[u]+1 d[u] d u 1 del q[0] q[0] q 0 for i in range(n):
    print i+1,d[i] i range(n) range n print i+1 i 1 d[i] d i u = q[0] q[0] u q = [] [] q u = entry[0]-1 entry[0]-1 u d = [-1 for i in range(n)] [-1 for i in range(n)] d graph = [[] for i in range(n)] [[] for i in range(n)] graph n = int(raw_input()) int(raw_input()) n entry = map(int,raw_input().strip().split(' ')) map(int,raw_input().strip().split(' ')) entry t = 1 1 t v -= 1 1 v
n = int(raw_input())



graph = [[] for i in range(n)]
for i in range(n):
    entry = map(int,raw_input().strip().split(' '))
    u = entry[0]-1
    for v in entry[2:]:
        v -= 1
        graph[u].append(v)

d = [-1 for i in range(n)]
d[0] = 0
t = 1
q = []
q.append(0)
while len(q) > 0:
    u = q[0]
    for v in graph[u]:
        if d[v] == -1:
            q.append(v)
            d[v] = d[u]+1
    del q[0]

for i in range(n):
    print i+1,d[i]