from collections import deque

N = 100
n = 0
M = None
WHITE = 0
GRAY = 1
BLACK = 2
INF = float('inf')
d = None


def main():
    global n, M, d
    M = [[0 for _ in range(N)] for _ in range(N)]
    n = int(input())
    d = [INF for _ in range(n)]

    for _ in range(n):
        u, k, *v_s = map(int, input().split(' '))
        for j in range(k):
            M[u-1][v_s[j-1]-1] = 1

    bfs()

    for i in range(n):
        print('{} {}'.format(i+1, d[i] if d[i] != INF else -1))


def bfs():
    q = deque()
    q.appendleft(0)
    d[0] = 0

    while len(q) > 0:
        u = q.pop()
        for v in range(n):
            if M[u][v] == WHITE:
                continue
            if d[v] != INF:
                continue
            d[v] = GRAY
            d[v] = d[u] + 1
            q.appendleft(v)


if __name__ == '__main__':
    main()
 from collections import deque N = 100 N 100 n = 0 n 0 M = None M None WHITE = 0 WHITE 0 GRAY = 1 GRAY 1 BLACK = 2 BLACK 2 INF = float('inf') INF float('inf') float 'inf' d = None d None def main():
    global n, M, d
    M = [[0 for _ in range(N)] for _ in range(N)]
    n = int(input())
    d = [INF for _ in range(n)]

    for _ in range(n):
        u, k, *v_s = map(int, input().split(' '))
        for j in range(k):
            M[u-1][v_s[j-1]-1] = 1

    bfs()

    for i in range(n):
        print('{} {}'.format(i+1, d[i] if d[i] != INF else -1)) main global n, M, d [0 for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0 for _ in range(N)] M = [[0 for _ in range(N)] for _ in range(N)] M [[0 for _ in range(N)] for _ in range(N)] n = int(input()) n int(input()) int input() input INF for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) INF d = [INF for _ in range(n)] d [INF for _ in range(n)] for _ in range(n):
        u, k, *v_s = map(int, input().split(' '))
        for j in range(k):
            M[u-1][v_s[j-1]-1] = 1

     _ range(n) range n u, k, *v_s = map(int, input().split(' ')) u map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' k *v_s v_s for j in range(k):
            M[u-1][v_s[j-1]-1] = 1

     j range(k) range k M[u-1][v_s[j-1]-1] = 1 M[u-1][v_s[j-1]-1] [u-1] M u-1 u 1 v_s[j-1]-1 v_s[j-1] v_s j-1 j 1 1 1 bfs() bfs for i in range(n):
        print('{} {}'.format(i+1, d[i] if d[i] != INF else -1)) i range(n) range n print('{} {}'.format(i+1, d[i] if d[i] != INF else -1)) print '{} {}'.format(i+1, d[i] if d[i] != INF else -1) '{} {}'.format '{} {}' format i+1 i 1 d[i] if d[i] != INF else -1 d[i] != INF d[i] d i INF d[i] d i -1 def bfs():
    q = deque()
    q.appendleft(0)
    d[0] = 0

    while len(q) > 0:
        u = q.pop()
        for v in range(n):
            if M[u][v] == WHITE:
                continue
            if d[v] != INF:
                continue
            d[v] = GRAY
            d[v] = d[u] + 1
            q.appendleft(v) bfs q = deque() q deque() deque q.appendleft(0) q.appendleft q appendleft 0 d[0] = 0 d[0] d 0 0 while len(q) > 0:
        u = q.pop()
        for v in range(n):
            if M[u][v] == WHITE:
                continue
            if d[v] != INF:
                continue
            d[v] = GRAY
            d[v] = d[u] + 1
            q.appendleft(v) len(q) > 0 len(q) len q 0 u = q.pop() u q.pop() q.pop q pop for v in range(n):
            if M[u][v] == WHITE:
                continue
            if d[v] != INF:
                continue
            d[v] = GRAY
            d[v] = d[u] + 1
            q.appendleft(v) v range(n) range n if M[u][v] == WHITE:
                continue
             M[u][v] == WHITE M[u][v] [u] M u v WHITE continue if d[v] != INF:
                continue
             d[v] != INF d[v] d v INF continue d[v] = GRAY d[v] d v GRAY d[v] = d[u] + 1 d[v] d v d[u] + 1 d[u] d u 1 q.appendleft(v) q.appendleft q appendleft v if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main M = None None M N = 100 100 N def bfs():
    q = deque()
    q.appendleft(0)
    d[0] = 0

    while len(q) > 0:
        u = q.pop()
        for v in range(n):
            if M[u][v] == WHITE:
                continue
            if d[v] != INF:
                continue
            d[v] = GRAY
            d[v] = d[u] + 1
            q.appendleft(v) def bfs():
    q = deque()
    q.appendleft(0)
    d[0] = 0

    while len(q) > 0:
        u = q.pop()
        for v in range(n):
            if M[u][v] == WHITE:
                continue
            if d[v] != INF:
                continue
            d[v] = GRAY
            d[v] = d[u] + 1
            q.appendleft(v) bfs WHITE = 0 0 WHITE d = None None d BLACK = 2 2 BLACK INF = float('inf') float('inf') INF def main():
    global n, M, d
    M = [[0 for _ in range(N)] for _ in range(N)]
    n = int(input())
    d = [INF for _ in range(n)]

    for _ in range(n):
        u, k, *v_s = map(int, input().split(' '))
        for j in range(k):
            M[u-1][v_s[j-1]-1] = 1

    bfs()

    for i in range(n):
        print('{} {}'.format(i+1, d[i] if d[i] != INF else -1)) def main():
    global n, M, d
    M = [[0 for _ in range(N)] for _ in range(N)]
    n = int(input())
    d = [INF for _ in range(n)]

    for _ in range(n):
        u, k, *v_s = map(int, input().split(' '))
        for j in range(k):
            M[u-1][v_s[j-1]-1] = 1

    bfs()

    for i in range(n):
        print('{} {}'.format(i+1, d[i] if d[i] != INF else -1)) main n = 0 0 n GRAY = 1 1 GRAY
from collections import deque

N = 100
n = 0
M = None
WHITE = 0
GRAY = 1
BLACK = 2
INF = float('inf')
d = None


def main():
    global n, M, d
    M = [[0 for _ in range(N)] for _ in range(N)]
    n = int(input())
    d = [INF for _ in range(n)]

    for _ in range(n):
        u, k, *v_s = map(int, input().split(' '))
        for j in range(k):
            M[u-1][v_s[j-1]-1] = 1

    bfs()

    for i in range(n):
        print('{} {}'.format(i+1, d[i] if d[i] != INF else -1))


def bfs():
    q = deque()
    q.appendleft(0)
    d[0] = 0

    while len(q) > 0:
        u = q.pop()
        for v in range(n):
            if M[u][v] == WHITE:
                continue
            if d[v] != INF:
                continue
            d[v] = GRAY
            d[v] = d[u] + 1
            q.appendleft(v)


if __name__ == '__main__':
    main()

