n = int(raw_input())

d = [0] * n
f = [0] * n
M = [[0]*n for _ in xrange(n)]
color = [0] * n
tt = 0
WHITE = 0
GRAY = 1
BLACK = 2

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

def dfs():
    for u in xrange(n):
        if color[u] == WHITE:
            dfs_visit(u)
    for u in xrange(n):
        print "{} {} {}".format(u+1, d[u], f[u])
    return 0

def main():
    for i in xrange(n):
        a = map(int, raw_input().split())
        u = a[0]-1
        k = a[1]
        for j in xrange(k):
            v = a[j+2] -  1
            M[u][v] = 1
    
    dfs()
    return 0

main() n = int(raw_input()) n int(raw_input()) int raw_input() raw_input d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n [0]*n for _ in xrange(n) for _ in xrange(n) _ xrange(n) xrange n for _ in xrange(n) [0]*n [0] 0 n M = [[0]*n for _ in xrange(n)] M [[0]*n for _ in xrange(n)] color = [0] * n color [0] * n [0] 0 n tt = 0 tt 0 WHITE = 0 WHITE 0 GRAY = 1 GRAY 1 BLACK = 2 BLACK 2 def dfs_visit(u):
    global tt
    color[u] = GRAY
    tt += 1
    d[u] = tt
    for v in xrange(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] = BLACK
    tt += 1
    f[u] = tt
    return 0 dfs_visit global tt color[u] = GRAY color[u] color u GRAY tt += 1 tt 1 d[u] = tt d[u] d u tt for v in xrange(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
     v xrange(n) xrange n if M[u][v] == 0:
            continue
         M[u][v] == 0 M[u][v] [u] M u v 0 continue if color[v] == WHITE:
            dfs_visit(v)
     color[v] == WHITE color[v] color v WHITE dfs_visit(v) dfs_visit v color[u] = BLACK color[u] color u BLACK tt += 1 tt 1 f[u] = tt f[u] f u tt return 0 0 u u def dfs():
    for u in xrange(n):
        if color[u] == WHITE:
            dfs_visit(u)
    for u in xrange(n):
        print "{} {} {}".format(u+1, d[u], f[u])
    return 0 dfs for u in xrange(n):
        if color[u] == WHITE:
            dfs_visit(u)
     u xrange(n) xrange n if color[u] == WHITE:
            dfs_visit(u)
     color[u] == WHITE color[u] color u WHITE dfs_visit(u) dfs_visit u for u in xrange(n):
        print "{} {} {}".format(u+1, d[u], f[u])
     u xrange(n) xrange n print "{} {} {}".format(u+1, d[u], f[u]) "{} {} {}".format "{} {} {}" format u+1 u 1 d[u] d u f[u] f u return 0 0 def main():
    for i in xrange(n):
        a = map(int, raw_input().split())
        u = a[0]-1
        k = a[1]
        for j in xrange(k):
            v = a[j+2] -  1
            M[u][v] = 1
    
    dfs()
    return 0 main for i in xrange(n):
        a = map(int, raw_input().split())
        u = a[0]-1
        k = a[1]
        for j in xrange(k):
            v = a[j+2] -  1
            M[u][v] = 1
    
     i xrange(n) xrange n a = map(int, raw_input().split()) a map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split u = a[0]-1 u a[0]-1 a[0] a 0 1 k = a[1] k a[1] a 1 for j in xrange(k):
            v = a[j+2] -  1
            M[u][v] = 1
    
     j xrange(k) xrange k v = a[j+2] -  1 v a[j+2] -  1 a[j+2] a j+2 j 2 1 M[u][v] = 1 M[u][v] [u] M u v 1 dfs() dfs return 0 0 main() main f = [0] * n [0] * n f color = [0] * n [0] * n color tt = 0 0 tt M = [[0]*n for _ in xrange(n)] [[0]*n for _ in xrange(n)] M BLACK = 2 2 BLACK GRAY = 1 1 GRAY def dfs():
    for u in xrange(n):
        if color[u] == WHITE:
            dfs_visit(u)
    for u in xrange(n):
        print "{} {} {}".format(u+1, d[u], f[u])
    return 0 def dfs():
    for u in xrange(n):
        if color[u] == WHITE:
            dfs_visit(u)
    for u in xrange(n):
        print "{} {} {}".format(u+1, d[u], f[u])
    return 0 dfs n = int(raw_input()) int(raw_input()) n def main():
    for i in xrange(n):
        a = map(int, raw_input().split())
        u = a[0]-1
        k = a[1]
        for j in xrange(k):
            v = a[j+2] -  1
            M[u][v] = 1
    
    dfs()
    return 0 def main():
    for i in xrange(n):
        a = map(int, raw_input().split())
        u = a[0]-1
        k = a[1]
        for j in xrange(k):
            v = a[j+2] -  1
            M[u][v] = 1
    
    dfs()
    return 0 main def dfs_visit(u):
    global tt
    color[u] = GRAY
    tt += 1
    d[u] = tt
    for v in xrange(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] = BLACK
    tt += 1
    f[u] = tt
    return 0 def dfs_visit(u):
    global tt
    color[u] = GRAY
    tt += 1
    d[u] = tt
    for v in xrange(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] = BLACK
    tt += 1
    f[u] = tt
    return 0 dfs_visit WHITE = 0 0 WHITE d = [0] * n [0] * n d
n = int(raw_input())

d = [0] * n
f = [0] * n
M = [[0]*n for _ in xrange(n)]
color = [0] * n
tt = 0
WHITE = 0
GRAY = 1
BLACK = 2

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

def dfs():
    for u in xrange(n):
        if color[u] == WHITE:
            dfs_visit(u)
    for u in xrange(n):
        print "{} {} {}".format(u+1, d[u], f[u])
    return 0

def main():
    for i in xrange(n):
        a = map(int, raw_input().split())
        u = a[0]-1
        k = a[1]
        for j in xrange(k):
            v = a[j+2] -  1
            M[u][v] = 1
    
    dfs()
    return 0

main()