#include<iostream>
using namespace std;
#define NIL -1
int n,ch[200],V[200][200],d[200],a;
void count(int x,int reach){
    d[x]=reach;
    for(int i=1;i<=ch[x];i++){
        int p=V[x][i];
        if(d[p]==NIL||d[p]>reach+1) count(p,reach+1);
    }
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a>>ch[i];
        d[i]=NIL;
        for(int j=1;j<=ch[i];j++){
            cin>>V[i][j];
        }
    }
    count(1,0);
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<d[i]<<endl;
    }
}
