import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def bfs(adj, nxt, dis, sumi, kyori):
    nnxt = []
    for u in nxt:
        sumi[u] = True
        dis[u] = kyori

    for u in nxt:
        for v in adj[u]:
            if not sumi[v]:
                nnxt.append(v)

    return nnxt, kyori + 1

def solve():
    n = int(input())
    adj = [None] * n
    for i in range(n):
        u, k, *vs = [int(j) - 1 for j in input().split()]
        adj[u] = vs

    # debug(adj, locals())

    sumi = [False] * n
    dis = [-1] * n
    nxt = [0]
    kyori = 0

    while nxt:
        nxt, kyori = bfs(adj, nxt, dis, sumi, kyori)

    for i in range(n):
        print(i + 1, dis[i])

    pass

if __name__ == '__main__':
    solve() import sys sys def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None debug for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None name val table.items() table.items table items if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None x is val x val print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) print 'DEBUG:{} -> {}'.format(name, val) 'DEBUG:{} -> {}'.format 'DEBUG:{} -> {}' format name val file=sys.stderr file sys.stderr sys stderr return None None x x table table def bfs(adj, nxt, dis, sumi, kyori):
    nnxt = []
    for u in nxt:
        sumi[u] = True
        dis[u] = kyori

    for u in nxt:
        for v in adj[u]:
            if not sumi[v]:
                nnxt.append(v)

    return nnxt, kyori + 1 bfs nnxt = [] nnxt [] for u in nxt:
        sumi[u] = True
        dis[u] = kyori

     u nxt sumi[u] = True sumi[u] sumi u True dis[u] = kyori dis[u] dis u kyori for u in nxt:
        for v in adj[u]:
            if not sumi[v]:
                nnxt.append(v)

     u nxt for v in adj[u]:
            if not sumi[v]:
                nnxt.append(v)

     v adj[u] adj u if not sumi[v]:
                nnxt.append(v)

     not sumi[v] sumi[v] sumi v nnxt.append(v) nnxt.append nnxt append v return nnxt, kyori + 1 return nnxt, kyori + 1 nnxt kyori + 1 kyori 1 adj adj nxt nxt dis dis sumi sumi kyori kyori def solve():
    n = int(input())
    adj = [None] * n
    for i in range(n):
        u, k, *vs = [int(j) - 1 for j in input().split()]
        adj[u] = vs

    # debug(adj, locals())

    sumi = [False] * n
    dis = [-1] * n
    nxt = [0]
    kyori = 0

    while nxt:
        nxt, kyori = bfs(adj, nxt, dis, sumi, kyori)

    for i in range(n):
        print(i + 1, dis[i])

    pass solve n = int(input()) n int(input()) int input() input adj = [None] * n adj [None] * n [None] None n for i in range(n):
        u, k, *vs = [int(j) - 1 for j in input().split()]
        adj[u] = vs

    # debug(adj, locals())

     i range(n) range n int(j) - 1 for j in input().split() for j in input().split() j input().split() ().split () input split for j in input().split() int(j) - 1 int(j) int j 1 u, k, *vs = [int(j) - 1 for j in input().split()] u [int(j) - 1 for j in input().split()] k *vs vs adj[u] = vs adj[u] adj u vs sumi = [False] * n sumi [False] * n [False] False n dis = [-1] * n dis [-1] * n [-1] -1 n nxt = [0] nxt [0] 0 kyori = 0 kyori 0 while nxt:
        nxt, kyori = bfs(adj, nxt, dis, sumi, kyori)

     nxt nxt, kyori = bfs(adj, nxt, dis, sumi, kyori) nxt bfs(adj, nxt, dis, sumi, kyori) bfs adj nxt dis sumi kyori kyori for i in range(n):
        print(i + 1, dis[i])

     i range(n) range n print(i + 1, dis[i]) print i + 1 i 1 dis[i] dis i if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None debug def solve():
    n = int(input())
    adj = [None] * n
    for i in range(n):
        u, k, *vs = [int(j) - 1 for j in input().split()]
        adj[u] = vs

    # debug(adj, locals())

    sumi = [False] * n
    dis = [-1] * n
    nxt = [0]
    kyori = 0

    while nxt:
        nxt, kyori = bfs(adj, nxt, dis, sumi, kyori)

    for i in range(n):
        print(i + 1, dis[i])

    pass def solve():
    n = int(input())
    adj = [None] * n
    for i in range(n):
        u, k, *vs = [int(j) - 1 for j in input().split()]
        adj[u] = vs

    # debug(adj, locals())

    sumi = [False] * n
    dis = [-1] * n
    nxt = [0]
    kyori = 0

    while nxt:
        nxt, kyori = bfs(adj, nxt, dis, sumi, kyori)

    for i in range(n):
        print(i + 1, dis[i])

    pass solve def bfs(adj, nxt, dis, sumi, kyori):
    nnxt = []
    for u in nxt:
        sumi[u] = True
        dis[u] = kyori

    for u in nxt:
        for v in adj[u]:
            if not sumi[v]:
                nnxt.append(v)

    return nnxt, kyori + 1 def bfs(adj, nxt, dis, sumi, kyori):
    nnxt = []
    for u in nxt:
        sumi[u] = True
        dis[u] = kyori

    for u in nxt:
        for v in adj[u]:
            if not sumi[v]:
                nnxt.append(v)

    return nnxt, kyori + 1 bfs
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def bfs(adj, nxt, dis, sumi, kyori):
    nnxt = []
    for u in nxt:
        sumi[u] = True
        dis[u] = kyori

    for u in nxt:
        for v in adj[u]:
            if not sumi[v]:
                nnxt.append(v)

    return nnxt, kyori + 1

def solve():
    n = int(input())
    adj = [None] * n
    for i in range(n):
        u, k, *vs = [int(j) - 1 for j in input().split()]
        adj[u] = vs

    # debug(adj, locals())

    sumi = [False] * n
    dis = [-1] * n
    nxt = [0]
    kyori = 0

    while nxt:
        nxt, kyori = bfs(adj, nxt, dis, sumi, kyori)

    for i in range(n):
        print(i + 1, dis[i])

    pass

if __name__ == '__main__':
    solve()