n=int(input())
ne=[[] for _ in range(n+1)]
for _ in range(n):
    u,k,*v=map(int,input().split())
    ne[u]=v
dis=[-1]*(n+1)
dis[1]=0
q=[1]
while q:
    p=q.pop(0)
    for e in ne[p]:
        if dis[e]==-1:
            dis[e]=dis[p]+1
            q.append(e)
for i in range(1,n+1):
    print(i,dis[i]) n=int(input()) n int(input()) int input() input [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] ne=[[] for _ in range(n+1)] ne [[] for _ in range(n+1)] for _ in range(n):
    u,k,*v=map(int,input().split())
    ne[u]=v _ range(n) range n u,k,*v=map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split k *v v ne[u]=v ne[u] ne u v dis=[-1]*(n+1) dis [-1]*(n+1) [-1] -1 n+1 n 1 dis[1]=0 dis[1] dis 1 0 q=[1] q [1] 1 while q:
    p=q.pop(0)
    for e in ne[p]:
        if dis[e]==-1:
            dis[e]=dis[p]+1
            q.append(e) q p=q.pop(0) p q.pop(0) q.pop q pop 0 for e in ne[p]:
        if dis[e]==-1:
            dis[e]=dis[p]+1
            q.append(e) e ne[p] ne p if dis[e]==-1:
            dis[e]=dis[p]+1
            q.append(e) dis[e]==-1 dis[e] dis e -1 dis[e]=dis[p]+1 dis[e] dis e dis[p]+1 dis[p] dis p 1 q.append(e) q.append q append e for i in range(1,n+1):
    print(i,dis[i]) i range(1,n+1) range 1 n+1 n 1 print(i,dis[i]) print i dis[i] dis i u,k,*v=map(int,input().split()) map(int,input().split()) u q=[1] [1] q k,*v=map(int,input().split()) map(int,input().split()) k ne=[[] for _ in range(n+1)] [[] for _ in range(n+1)] ne n=int(input()) int(input()) n p=q.pop(0) q.pop(0) p dis=[-1]*(n+1) [-1]*(n+1) dis
n=int(input())
ne=[[] for _ in range(n+1)]
for _ in range(n):
    u,k,*v=map(int,input().split())
    ne[u]=v
dis=[-1]*(n+1)
dis[1]=0
q=[1]
while q:
    p=q.pop(0)
    for e in ne[p]:
        if dis[e]==-1:
            dis[e]=dis[p]+1
            q.append(e)
for i in range(1,n+1):
    print(i,dis[i])
