from collections import deque


N = 100
WHITE = 0
GRAY = 1
BLACK = 2

M = [[0 for _ in range(N)] for _ in range(N)]
color = [0 for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
nt = [0 for _ in range(N)]
tt = 0


def main():
    n = int(input())
    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

    dfs(n)

    for i in range(n):
        print('{} {} {}'.format(i+1, d[i], f[i]))


def dfs(n):
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(n, u)


def dfs_visit(n, r):
    global tt
    color[r] = GRAY
    tt += 1
    d[r] = tt
    for v in range(0, n):
        if M[r][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(n, v)
    color[r] = BLACK
    tt += 1
    f[r] = tt


if __name__ == '__main__':
    main()
 from collections import deque N = 100 N 100 WHITE = 0 WHITE 0 GRAY = 1 GRAY 1 BLACK = 2 BLACK 2 [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)] 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 color = [0 for _ in range(N)] color [0 for _ in range(N)] 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 d = [0 for _ in range(N)] d [0 for _ in range(N)] 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 f = [0 for _ in range(N)] f [0 for _ in range(N)] 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 nt = [0 for _ in range(N)] nt [0 for _ in range(N)] tt = 0 tt 0 def main():
    n = int(input())
    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

    dfs(n)

    for i in range(n):
        print('{} {} {}'.format(i+1, d[i], f[i])) main n = int(input()) n int(input()) int input() input 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 dfs(n) dfs n for i in range(n):
        print('{} {} {}'.format(i+1, d[i], f[i])) i range(n) range n print('{} {} {}'.format(i+1, d[i], f[i])) print '{} {} {}'.format(i+1, d[i], f[i]) '{} {} {}'.format '{} {} {}' format i+1 i 1 d[i] d i f[i] f i def dfs(n):
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(n, u) dfs for u in range(n):
        if color[u] == WHITE:
            dfs_visit(n, u) u range(n) range n if color[u] == WHITE:
            dfs_visit(n, u) color[u] == WHITE color[u] color u WHITE dfs_visit(n, u) dfs_visit n u n n def dfs_visit(n, r):
    global tt
    color[r] = GRAY
    tt += 1
    d[r] = tt
    for v in range(0, n):
        if M[r][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(n, v)
    color[r] = BLACK
    tt += 1
    f[r] = tt dfs_visit global tt color[r] = GRAY color[r] color r GRAY tt += 1 tt 1 d[r] = tt d[r] d r tt for v in range(0, n):
        if M[r][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(n, v)
     v range(0, n) range 0 n if M[r][v] == 0:
            continue
         M[r][v] == 0 M[r][v] [r] M r v 0 continue if color[v] == WHITE:
            dfs_visit(n, v)
     color[v] == WHITE color[v] color v WHITE dfs_visit(n, v) dfs_visit n v color[r] = BLACK color[r] color r BLACK tt += 1 tt 1 f[r] = tt f[r] f r tt n n r r if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main GRAY = 1 1 GRAY nt = [0 for _ in range(N)] [0 for _ in range(N)] nt N = 100 100 N def dfs(n):
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(n, u) def dfs(n):
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(n, u) dfs color = [0 for _ in range(N)] [0 for _ in range(N)] color d = [0 for _ in range(N)] [0 for _ in range(N)] d def main():
    n = int(input())
    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

    dfs(n)

    for i in range(n):
        print('{} {} {}'.format(i+1, d[i], f[i])) def main():
    n = int(input())
    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

    dfs(n)

    for i in range(n):
        print('{} {} {}'.format(i+1, d[i], f[i])) main WHITE = 0 0 WHITE tt = 0 0 tt def dfs_visit(n, r):
    global tt
    color[r] = GRAY
    tt += 1
    d[r] = tt
    for v in range(0, n):
        if M[r][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(n, v)
    color[r] = BLACK
    tt += 1
    f[r] = tt def dfs_visit(n, r):
    global tt
    color[r] = GRAY
    tt += 1
    d[r] = tt
    for v in range(0, n):
        if M[r][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(n, v)
    color[r] = BLACK
    tt += 1
    f[r] = tt dfs_visit BLACK = 2 2 BLACK f = [0 for _ in range(N)] [0 for _ in range(N)] f M = [[0 for _ in range(N)] for _ in range(N)] [[0 for _ in range(N)] for _ in range(N)] M
from collections import deque


N = 100
WHITE = 0
GRAY = 1
BLACK = 2

M = [[0 for _ in range(N)] for _ in range(N)]
color = [0 for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
nt = [0 for _ in range(N)]
tt = 0


def main():
    n = int(input())
    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

    dfs(n)

    for i in range(n):
        print('{} {} {}'.format(i+1, d[i], f[i]))


def dfs(n):
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(n, u)


def dfs_visit(n, r):
    global tt
    color[r] = GRAY
    tt += 1
    d[r] = tt
    for v in range(0, n):
        if M[r][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(n, v)
    color[r] = BLACK
    tt += 1
    f[r] = tt


if __name__ == '__main__':
    main()

