#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from Queue import Queue
 
 
def main():
    num = int(stdin.readline())
 
    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])
 
    d = [-1] * num
    d[0] = 0
    q = Queue(100)
    q.put(0)
    while not q.empty():
        u = q.get()
        for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)
 
    for i, v in enumerate(d):
        print(i+1, v)
 
 
main() from __future__ import division, print_function from sys import stdin from Queue import Queue def main():
    num = int(stdin.readline())
 
    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])
 
    d = [-1] * num
    d[0] = 0
    q = Queue(100)
    q.put(0)
    while not q.empty():
        u = q.get()
        for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)
 
    for i, v in enumerate(d):
        print(i+1, v)
 
  main num = int(stdin.readline()) num int(stdin.readline()) int stdin.readline() stdin.readline stdin readline L = [] L [] for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])
 
     _ xrange(num) xrange num int(s) for s in stdin.readline().split()[2:] for s in stdin.readline().split()[2:] s stdin.readline().split()[2:] stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split 2: 2 for s in stdin.readline().split()[2:] int(s) int s L.append([int(s) for s in stdin.readline().split()[2:]]) L.append L append [int(s) for s in stdin.readline().split()[2:]] d = [-1] * num d [-1] * num [-1] -1 num d[0] = 0 d[0] d 0 0 q = Queue(100) q Queue(100) Queue 100 q.put(0) q.put q put 0 while not q.empty():
        u = q.get()
        for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)
 
     not q.empty() q.empty() q.empty q empty u = q.get() u q.get() q.get q get for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)
 
     v L[u] L u if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)
 
     d[v-1] < 0 d[v-1] d v-1 v 1 0 d[v-1] = d[u] + 1 d[v-1] d v-1 v 1 d[u] + 1 d[u] d u 1 q.put(v-1) q.put q put v-1 v 1 for i, v in enumerate(d):
        print(i+1, v)
 
  i v enumerate(d) enumerate d print(i+1, v) print i+1 i 1 v main() main def main():
    num = int(stdin.readline())
 
    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])
 
    d = [-1] * num
    d[0] = 0
    q = Queue(100)
    q.put(0)
    while not q.empty():
        u = q.get()
        for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)
 
    for i, v in enumerate(d):
        print(i+1, v)
 
  def main():
    num = int(stdin.readline())
 
    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])
 
    d = [-1] * num
    d[0] = 0
    q = Queue(100)
    q.put(0)
    while not q.empty():
        u = q.get()
        for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)
 
    for i, v in enumerate(d):
        print(i+1, v)
 
  main
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from Queue import Queue
 
 
def main():
    num = int(stdin.readline())
 
    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])
 
    d = [-1] * num
    d[0] = 0
    q = Queue(100)
    q.put(0)
    while not q.empty():
        u = q.get()
        for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)
 
    for i, v in enumerate(d):
        print(i+1, v)
 
 
main()