n = int(raw_input())
G = [[0 for i in range(n+1)] for j in range(n+1)]
d = [-1 for i in range(n+1)]

for i in range(n):
    v = map(int, raw_input().split())
    for j in range(v[1]):
        G[v[0]][v[2+j]] = 1

flag = [0 for i in range(n+1)]
tn = [[0 for i in range(n+1)] for j in range(n+1)]
tn[0][1] = 1
r = 0
for i in range(n):
    for j in range(1, n+1):
        if flag[j] == 0 and tn[i][j] == 1:
            flag[j] = 1
            d[j] = r
            for k in range(1, n+1):
                if G[j][k] == 1:
                    tn[i+1][k] = 1
    r += 1

for i in range(1, n+1):
    print(str(i) + " " + str(d[i])) n = int(raw_input()) n int(raw_input()) int raw_input() raw_input [0 for i in range(n+1)] for j in range(n+1) for j in range(n+1) j range(n+1) range n+1 n 1 for j in range(n+1) [0 for i in range(n+1)] G = [[0 for i in range(n+1)] for j in range(n+1)] G [[0 for i in range(n+1)] for j in range(n+1)] -1 for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) -1 d = [-1 for i in range(n+1)] d [-1 for i in range(n+1)] for i in range(n):
    v = map(int, raw_input().split())
    for j in range(v[1]):
        G[v[0]][v[2+j]] = 1 i range(n) range n v = map(int, raw_input().split()) v map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split for j in range(v[1]):
        G[v[0]][v[2+j]] = 1 j range(v[1]) range v[1] v 1 G[v[0]][v[2+j]] = 1 G[v[0]][v[2+j]] [v[0]] G v[0] v 0 v[2+j] v 2+j 2 j 1 0 for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) 0 flag = [0 for i in range(n+1)] flag [0 for i in range(n+1)] [0 for i in range(n+1)] for j in range(n+1) for j in range(n+1) j range(n+1) range n+1 n 1 for j in range(n+1) [0 for i in range(n+1)] tn = [[0 for i in range(n+1)] for j in range(n+1)] tn [[0 for i in range(n+1)] for j in range(n+1)] tn[0][1] = 1 tn[0][1] [0] tn 0 1 1 r = 0 r 0 for i in range(n):
    for j in range(1, n+1):
        if flag[j] == 0 and tn[i][j] == 1:
            flag[j] = 1
            d[j] = r
            for k in range(1, n+1):
                if G[j][k] == 1:
                    tn[i+1][k] = 1
    r += 1 i range(n) range n for j in range(1, n+1):
        if flag[j] == 0 and tn[i][j] == 1:
            flag[j] = 1
            d[j] = r
            for k in range(1, n+1):
                if G[j][k] == 1:
                    tn[i+1][k] = 1
     j range(1, n+1) range 1 n+1 n 1 if flag[j] == 0 and tn[i][j] == 1:
            flag[j] = 1
            d[j] = r
            for k in range(1, n+1):
                if G[j][k] == 1:
                    tn[i+1][k] = 1
     flag[j] == 0 and tn[i][j] == 1 flag[j] == 0 flag[j] flag j 0 tn[i][j] == 1 tn[i][j] [i] tn i j 1 flag[j] = 1 flag[j] flag j 1 d[j] = r d[j] d j r for k in range(1, n+1):
                if G[j][k] == 1:
                    tn[i+1][k] = 1
     k range(1, n+1) range 1 n+1 n 1 if G[j][k] == 1:
                    tn[i+1][k] = 1
     G[j][k] == 1 G[j][k] [j] G j k 1 tn[i+1][k] = 1 tn[i+1][k] [i+1] tn i+1 i 1 k 1 r += 1 r 1 for i in range(1, n+1):
    print(str(i) + " " + str(d[i])) i range(1, n+1) range 1 n+1 n 1 print(str(i) + " " + str(d[i])) print str(i) + " " + str(d[i]) str(i) + " " str(i) str i " " str(d[i]) str d[i] d i tn = [[0 for i in range(n+1)] for j in range(n+1)] [[0 for i in range(n+1)] for j in range(n+1)] tn r = 0 0 r v = map(int, raw_input().split()) map(int, raw_input().split()) v d = [-1 for i in range(n+1)] [-1 for i in range(n+1)] d n = int(raw_input()) int(raw_input()) n flag = [0 for i in range(n+1)] [0 for i in range(n+1)] flag r += 1 1 r G = [[0 for i in range(n+1)] for j in range(n+1)] [[0 for i in range(n+1)] for j in range(n+1)] G
n = int(raw_input())
G = [[0 for i in range(n+1)] for j in range(n+1)]
d = [-1 for i in range(n+1)]

for i in range(n):
    v = map(int, raw_input().split())
    for j in range(v[1]):
        G[v[0]][v[2+j]] = 1

flag = [0 for i in range(n+1)]
tn = [[0 for i in range(n+1)] for j in range(n+1)]
tn[0][1] = 1
r = 0
for i in range(n):
    for j in range(1, n+1):
        if flag[j] == 0 and tn[i][j] == 1:
            flag[j] = 1
            d[j] = r
            for k in range(1, n+1):
                if G[j][k] == 1:
                    tn[i+1][k] = 1
    r += 1

for i in range(1, n+1):
    print(str(i) + " " + str(d[i]))