n = int(raw_input())
d = [100 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]

def BFS(s):
	for e in range(n):
		if v[s][e] == 1:
			if d[e] > d[s] + 1:
				d[e] = d[s]+1
				BFS(e)

for i in range(n):
	G = map(int, raw_input().split())
	for j in range(G[1]):
		v[G[0]-1][G[j+2]-1] = 1
d[0] = 0

for i in range(n):
	BFS(i)
for i in range(n):
	if d[i] == 100:
		d[i] = -1
for i in range(n):
	print i+1, d[i] n = int(raw_input()) n int(raw_input()) int raw_input() raw_input 100 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 100 d = [100 for i in range(n)] d [100 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 G = [0 for i in range(n)] G [0 for i in range(n)] [0 for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [0 for i in range(n)] v = [[0 for i in range(n)] for j in range(n)] v [[0 for i in range(n)] for j in range(n)] def BFS(s):
	for e in range(n):
		if v[s][e] == 1:
			if d[e] > d[s] + 1:
				d[e] = d[s]+1
				BFS(e) BFS for e in range(n):
		if v[s][e] == 1:
			if d[e] > d[s] + 1:
				d[e] = d[s]+1
				BFS(e) e range(n) range n if v[s][e] == 1:
			if d[e] > d[s] + 1:
				d[e] = d[s]+1
				BFS(e) v[s][e] == 1 v[s][e] [s] v s e 1 if d[e] > d[s] + 1:
				d[e] = d[s]+1
				BFS(e) d[e] > d[s] + 1 d[e] d e d[s] + 1 d[s] d s 1 d[e] = d[s]+1 d[e] d e d[s]+1 d[s] d s 1 BFS(e) BFS e s s for i in range(n):
	G = map(int, raw_input().split())
	for j in range(G[1]):
		v[G[0]-1][G[j+2]-1] = 1 i range(n) range n G = map(int, raw_input().split()) G map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split for j in range(G[1]):
		v[G[0]-1][G[j+2]-1] = 1 j range(G[1]) range G[1] G 1 v[G[0]-1][G[j+2]-1] = 1 v[G[0]-1][G[j+2]-1] [G[0]-1] v G[0]-1 G[0] G 0 1 G[j+2]-1 G[j+2] G j+2 j 2 1 1 d[0] = 0 d[0] d 0 0 for i in range(n):
	BFS(i) i range(n) range n BFS(i) BFS i for i in range(n):
	if d[i] == 100:
		d[i] = -1 i range(n) range n if d[i] == 100:
		d[i] = -1 d[i] == 100 d[i] d i 100 d[i] = -1 d[i] d i -1 for i in range(n):
	print i+1, d[i] i range(n) range n print i+1 i 1 d[i] d i v = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] v n = int(raw_input()) int(raw_input()) n def BFS(s):
	for e in range(n):
		if v[s][e] == 1:
			if d[e] > d[s] + 1:
				d[e] = d[s]+1
				BFS(e) def BFS(s):
	for e in range(n):
		if v[s][e] == 1:
			if d[e] > d[s] + 1:
				d[e] = d[s]+1
				BFS(e) BFS G = [0 for i in range(n)] [0 for i in range(n)] G G = map(int, raw_input().split()) map(int, raw_input().split()) G d = [100 for i in range(n)] [100 for i in range(n)] d
n = int(raw_input())
d = [100 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]

def BFS(s):
	for e in range(n):
		if v[s][e] == 1:
			if d[e] > d[s] + 1:
				d[e] = d[s]+1
				BFS(e)

for i in range(n):
	G = map(int, raw_input().split())
	for j in range(G[1]):
		v[G[0]-1][G[j+2]-1] = 1
d[0] = 0

for i in range(n):
	BFS(i)
for i in range(n):
	if d[i] == 100:
		d[i] = -1
for i in range(n):
	print i+1, d[i]