using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{

    class Data
    {
        public int Dist;
        public Edge Edge;
        public Data(int dist, Edge edge)
        {
            Dist = dist;
            Edge = edge;
        }

        public static List<Data> SortByDist(List<Data> lst)
        {
            // TODO: 要確認
            lst.Sort((d1, d2) => (d1.Dist).CompareTo(d2.Dist));
            return lst;
        }
    }

    internal class Node
    {
        public List <Edge> Edges;
        public int Dist;
        public int No;
        
        public Node(int no)
        {
            this.No = no;
            Dist = int.MaxValue;
            Edges = new List<Edge>();
        }
    }

    internal class Edge
    {
        public int From;
        public int To;
        public int Cost;
       

        public Edge(int fr, int to, int cost = 0)
        {
            From = fr;
            To = to;
            Cost = cost;
        }

    }

    internal class Graph
    {
        public List<Node> Nodes;

        public Node this[int i]
        {
            set { Nodes[i] = value; }
            get { return Nodes[i]; }
        }

        public Graph(int N)
        {
            Nodes = new List<Node>();
            for (int i = 0; i < N; i++)
            {
                Nodes.Add(new Node(i));
            }
        }

    }

    internal class Solution
    {
        public int N;
        public Graph G;

        public void Run()
        {
            N = Input.ReadInt();
            G = new Graph(N);
            
            for (int i = 0; i < N; i++)
            {
                var line = Input.ReadIntArray();
                var o = line[1];
                for (int j = 0; j < o; j++)
                {
                    int fr = i;
                    int to = line[2 + j] - 1;
                    G[i].Edges.Add(new Edge(fr, to));
                }
            }

            RunGraph();
            for (int i = 0; i < N; i++)
            {
                var d = G[i].Dist == int.MaxValue ? -1 : G[i].Dist;
                Console.WriteLine("{0} {1}", i+1, d);
            }
        }

        public void RunGraph()
        {
            var q = new Queue<Data>();
            q.Enqueue(new Data(0, new Edge(-1, 0)));

            while (q.Count > 0)
            {
                var d = q.Dequeue();
                var e = d.Edge;
                var to = e.To;
                if(G[to].Dist < int.MaxValue) continue;
                G[to].Dist = d.Dist;
                foreach(var _e in G[to].Edges)
                    q.Enqueue(new Data(G[to].Dist + 1, _e));
            }
        }

    }

    
    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}


Measured memory_bytes: 10680