from collections import deque
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
nt = [0] * n

def next(u):
    for v in xrange(nt[u],n):
        nt[u] = v + 1
        if M[u][v] == 1:
            return v
    return -1

def dfs_visit(r):
    global tt
    S = deque([])
    S.append(r)
    color[r] = GRAY
    tt += 1
    d[r] = tt

    while len(S) > 0:
        u = S[len(S)-1]
        v = next(u)
        if v != -1:
            if color[v] == WHITE:
                color[v] = GRAY
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            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() from collections import deque 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 nt = [0] * n nt [0] * n [0] 0 n def next(u):
    for v in xrange(nt[u],n):
        nt[u] = v + 1
        if M[u][v] == 1:
            return v
    return -1 next for v in xrange(nt[u],n):
        nt[u] = v + 1
        if M[u][v] == 1:
            return v
     v xrange(nt[u],n) xrange nt[u] nt u n nt[u] = v + 1 nt[u] nt u v + 1 v 1 if M[u][v] == 1:
            return v
     M[u][v] == 1 M[u][v] [u] M u v 1 return v v return -1 -1 u u def dfs_visit(r):
    global tt
    S = deque([])
    S.append(r)
    color[r] = GRAY
    tt += 1
    d[r] = tt

    while len(S) > 0:
        u = S[len(S)-1]
        v = next(u)
        if v != -1:
            if color[v] == WHITE:
                color[v] = GRAY
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            color[u] = BLACK
            tt += 1
            f[u] = tt

    return 0 dfs_visit global tt S = deque([]) S deque([]) deque [] S.append(r) S.append S append r color[r] = GRAY color[r] color r GRAY tt += 1 tt 1 d[r] = tt d[r] d r tt while len(S) > 0:
        u = S[len(S)-1]
        v = next(u)
        if v != -1:
            if color[v] == WHITE:
                color[v] = GRAY
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            color[u] = BLACK
            tt += 1
            f[u] = tt

     len(S) > 0 len(S) len S 0 u = S[len(S)-1] u S[len(S)-1] S len(S)-1 len(S) len S 1 v = next(u) v next(u) next u if v != -1:
            if color[v] == WHITE:
                color[v] = GRAY
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            color[u] = BLACK
            tt += 1
            f[u] = tt

     v != -1 v -1 if color[v] == WHITE:
                color[v] = GRAY
                tt += 1
                d[v] = tt
                S.append(v)
         color[v] == WHITE color[v] color v WHITE color[v] = GRAY color[v] color v GRAY tt += 1 tt 1 d[v] = tt d[v] d v tt S.append(v) S.append S append v S.pop() S.pop S pop color[u] = BLACK color[u] color u BLACK tt += 1 tt 1 f[u] = tt f[u] f u tt return 0 0 r r 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 def next(u):
    for v in xrange(nt[u],n):
        nt[u] = v + 1
        if M[u][v] == 1:
            return v
    return -1 def next(u):
    for v in xrange(nt[u],n):
        nt[u] = v + 1
        if M[u][v] == 1:
            return v
    return -1 next 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 d = [0] * n [0] * n d 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 WHITE = 0 0 WHITE BLACK = 2 2 BLACK GRAY = 1 1 GRAY f = [0] * n [0] * n f tt = 0 0 tt M = [[0]*n for _ in xrange(n)] [[0]*n for _ in xrange(n)] M nt = [0] * n [0] * n nt def dfs_visit(r):
    global tt
    S = deque([])
    S.append(r)
    color[r] = GRAY
    tt += 1
    d[r] = tt

    while len(S) > 0:
        u = S[len(S)-1]
        v = next(u)
        if v != -1:
            if color[v] == WHITE:
                color[v] = GRAY
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            color[u] = BLACK
            tt += 1
            f[u] = tt

    return 0 def dfs_visit(r):
    global tt
    S = deque([])
    S.append(r)
    color[r] = GRAY
    tt += 1
    d[r] = tt

    while len(S) > 0:
        u = S[len(S)-1]
        v = next(u)
        if v != -1:
            if color[v] == WHITE:
                color[v] = GRAY
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            color[u] = BLACK
            tt += 1
            f[u] = tt

    return 0 dfs_visit color = [0] * n [0] * n color
from collections import deque
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
nt = [0] * n

def next(u):
    for v in xrange(nt[u],n):
        nt[u] = v + 1
        if M[u][v] == 1:
            return v
    return -1

def dfs_visit(r):
    global tt
    S = deque([])
    S.append(r)
    color[r] = GRAY
    tt += 1
    d[r] = tt

    while len(S) > 0:
        u = S[len(S)-1]
        v = next(u)
        if v != -1:
            if color[v] == WHITE:
                color[v] = GRAY
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            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()