n = int(input())

m = [[0 for _ in range(n+1)] for _ in range(n+1)]
#mm = [[] for _ in range(n+1)]

for _ in range(n):
	tmp = [int(x) for x in input().split()]
	u,k,l = tmp[0],tmp[1],tmp[2:]
	#mm[u] += tmp[2:]
	for x in l:
		m[u][x] = 1
		
dp = [float('inf') for _ in range(n+1)]
dp[1] = 0
queue = [1]

while queue:
	t = queue.pop(0)
	for i,x in enumerate(m[t]):
		if x == 1:
			if dp[i] > dp[t] + 1:
				dp[i] = dp[t] + 1
				queue.append(i)
			else:
				pass
		else:
			pass
			
for i,x in enumerate(dp):
	if i == 0:
		pass
	else:
		if x == float('inf'):
			print(i, -1)
		else:
			print(i, x)
			

	 n = int(input()) n int(input()) int input() input [0 for _ in range(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 for _ in range(n+1)] m = [[0 for _ in range(n+1)] for _ in range(n+1)] m [[0 for _ in range(n+1)] for _ in range(n+1)] for _ in range(n):
	tmp = [int(x) for x in input().split()]
	u,k,l = tmp[0],tmp[1],tmp[2:]
	#mm[u] += tmp[2:]
	for x in l:
		m[u][x] = 1
		 _ range(n) range n int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x tmp = [int(x) for x in input().split()] tmp [int(x) for x in input().split()] u,k,l = tmp[0],tmp[1],tmp[2:] u tmp[0] tmp 0 k tmp[1] tmp 1 l tmp[2:] tmp 2: 2 for x in l:
		m[u][x] = 1
		 x l m[u][x] = 1 m[u][x] [u] m u x 1 float('inf') for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) float('inf') float 'inf' dp = [float('inf') for _ in range(n+1)] dp [float('inf') for _ in range(n+1)] dp[1] = 0 dp[1] dp 1 0 queue = [1] queue [1] 1 while queue:
	t = queue.pop(0)
	for i,x in enumerate(m[t]):
		if x == 1:
			if dp[i] > dp[t] + 1:
				dp[i] = dp[t] + 1
				queue.append(i)
			else:
				pass
		else:
			pass
			 queue t = queue.pop(0) t queue.pop(0) queue.pop queue pop 0 for i,x in enumerate(m[t]):
		if x == 1:
			if dp[i] > dp[t] + 1:
				dp[i] = dp[t] + 1
				queue.append(i)
			else:
				pass
		else:
			pass
			 i x enumerate(m[t]) enumerate m[t] m t if x == 1:
			if dp[i] > dp[t] + 1:
				dp[i] = dp[t] + 1
				queue.append(i)
			else:
				pass
		else:
			pass
			 x == 1 x 1 if dp[i] > dp[t] + 1:
				dp[i] = dp[t] + 1
				queue.append(i)
			else:
				pass
		 dp[i] > dp[t] + 1 dp[i] dp i dp[t] + 1 dp[t] dp t 1 dp[i] = dp[t] + 1 dp[i] dp i dp[t] + 1 dp[t] dp t 1 queue.append(i) queue.append queue append i for i,x in enumerate(dp):
	if i == 0:
		pass
	else:
		if x == float('inf'):
			print(i, -1)
		else:
			print(i, x)
			

	 i x enumerate(dp) enumerate dp if i == 0:
		pass
	else:
		if x == float('inf'):
			print(i, -1)
		else:
			print(i, x)
			

	 i == 0 i 0 if x == float('inf'):
			print(i, -1)
		else:
			print(i, x)
			

	 x == float('inf') x float('inf') float 'inf' print(i, -1) print i -1 print(i, x) print i x u,k,l = tmp[0],tmp[1],tmp[2:] tmp[0] u t = queue.pop(0) queue.pop(0) t l = tmp[0],tmp[1],tmp[2:] tmp[2:] l n = int(input()) int(input()) n tmp = [int(x) for x in input().split()] [int(x) for x in input().split()] tmp m = [[0 for _ in range(n+1)] for _ in range(n+1)] [[0 for _ in range(n+1)] for _ in range(n+1)] m queue = [1] [1] queue dp = [float('inf') for _ in range(n+1)] [float('inf') for _ in range(n+1)] dp k,l = tmp[0],tmp[1],tmp[2:] tmp[1] k
n = int(input())

m = [[0 for _ in range(n+1)] for _ in range(n+1)]
#mm = [[] for _ in range(n+1)]

for _ in range(n):
	tmp = [int(x) for x in input().split()]
	u,k,l = tmp[0],tmp[1],tmp[2:]
	#mm[u] += tmp[2:]
	for x in l:
		m[u][x] = 1
		
dp = [float('inf') for _ in range(n+1)]
dp[1] = 0
queue = [1]

while queue:
	t = queue.pop(0)
	for i,x in enumerate(m[t]):
		if x == 1:
			if dp[i] > dp[t] + 1:
				dp[i] = dp[t] + 1
				queue.append(i)
			else:
				pass
		else:
			pass
			
for i,x in enumerate(dp):
	if i == 0:
		pass
	else:
		if x == float('inf'):
			print(i, -1)
		else:
			print(i, x)
			

	
