N = input()
color = [0] * N
d = [0] * N
f = [0] * N
nt = [0] * N
m = [[0] * N for i in range(N)]
S = []
tt = 0

def next(u):
    global nt
    w = nt[u]
    for v in range(w, N):
        nt[u] = v + 1
        if( m[u][v] ):
            return v
    return -1

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

    while( len(S) != 0 ):
        u = S[-1]

        v = next(u)
        if ( v != -1 ):
            if ( color[v] == 0 ):
                color[v] = 1
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            color[u] = 2
            tt += 1
            f[u] = tt
        
def dfs():
    global color
    for u in range(N):
        if( color[u] == 0 ):
            dfs_visit(u)

if __name__ == '__main__':

    for i in range(N):
        v = map(int, raw_input().split())
        for j in v[2:]:
            m[i][j-1] = 1
    
    dfs()

    for i in range(N):
        print (i+1), d[i], f[i] N = input() N input() input color = [0] * N color [0] * N [0] 0 N d = [0] * N d [0] * N [0] 0 N f = [0] * N f [0] * N [0] 0 N nt = [0] * N nt [0] * N [0] 0 N [0] * N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [0] * N [0] 0 N m = [[0] * N for i in range(N)] m [[0] * N for i in range(N)] S = [] S [] tt = 0 tt 0 def next(u):
    global nt
    w = nt[u]
    for v in range(w, N):
        nt[u] = v + 1
        if( m[u][v] ):
            return v
    return -1 next global nt w = nt[u] w nt[u] nt u for v in range(w, N):
        nt[u] = v + 1
        if( m[u][v] ):
            return v
     v range(w, N) range w N nt[u] = v + 1 nt[u] nt u v + 1 v 1 if( m[u][v] ):
            return v
     m[u][v] [u] m u v return v v return -1 -1 u u def dfs_visit(r):
    global tt 
    S.append(r)
    color[r] = 1
    tt += 1
    d[r] = tt

    while( len(S) != 0 ):
        u = S[-1]

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

        v = next(u)
        if ( v != -1 ):
            if ( color[v] == 0 ):
                color[v] = 1
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            color[u] = 2
            tt += 1
            f[u] = tt
         len(S) != 0 len(S) len S 0 u = S[-1] u S[-1] S -1 v = next(u) v next(u) next u if ( v != -1 ):
            if ( color[v] == 0 ):
                color[v] = 1
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            color[u] = 2
            tt += 1
            f[u] = tt
         v != -1 v -1 if ( color[v] == 0 ):
                color[v] = 1
                tt += 1
                d[v] = tt
                S.append(v)
         color[v] == 0 color[v] color v 0 color[v] = 1 color[v] color v 1 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] = 2 color[u] color u 2 tt += 1 tt 1 f[u] = tt f[u] f u tt r r def dfs():
    global color
    for u in range(N):
        if( color[u] == 0 ):
            dfs_visit(u) dfs global color for u in range(N):
        if( color[u] == 0 ):
            dfs_visit(u) u range(N) range N if( color[u] == 0 ):
            dfs_visit(u) color[u] == 0 color[u] color u 0 dfs_visit(u) dfs_visit u if __name__ == '__main__':

    for i in range(N):
        v = map(int, raw_input().split())
        for j in v[2:]:
            m[i][j-1] = 1
    
    dfs()

    for i in range(N):
        print (i+1), d[i], f[i] __name__ == '__main__' __name__ '__main__' for i in range(N):
        v = map(int, raw_input().split())
        for j in v[2:]:
            m[i][j-1] = 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 v[2:]:
            m[i][j-1] = 1
    
     j v[2:] v 2: 2 m[i][j-1] = 1 m[i][j-1] [i] m i j-1 j 1 1 dfs() dfs for i in range(N):
        print (i+1), d[i], f[i] i range(N) range N print (i+1) print i+1 i 1 d[i] d i f[i] f i color = [0] * N [0] * N color d = [0] * N [0] * N d v = map(int, raw_input().split()) map(int, raw_input().split()) v def dfs():
    global color
    for u in range(N):
        if( color[u] == 0 ):
            dfs_visit(u) def dfs():
    global color
    for u in range(N):
        if( color[u] == 0 ):
            dfs_visit(u) dfs f = [0] * N [0] * N f nt = [0] * N [0] * N nt m = [[0] * N for i in range(N)] [[0] * N for i in range(N)] m S = [] [] S tt = 0 0 tt N = input() input() N def next(u):
    global nt
    w = nt[u]
    for v in range(w, N):
        nt[u] = v + 1
        if( m[u][v] ):
            return v
    return -1 def next(u):
    global nt
    w = nt[u]
    for v in range(w, N):
        nt[u] = v + 1
        if( m[u][v] ):
            return v
    return -1 next def dfs_visit(r):
    global tt 
    S.append(r)
    color[r] = 1
    tt += 1
    d[r] = tt

    while( len(S) != 0 ):
        u = S[-1]

        v = next(u)
        if ( v != -1 ):
            if ( color[v] == 0 ):
                color[v] = 1
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            color[u] = 2
            tt += 1
            f[u] = tt
         def dfs_visit(r):
    global tt 
    S.append(r)
    color[r] = 1
    tt += 1
    d[r] = tt

    while( len(S) != 0 ):
        u = S[-1]

        v = next(u)
        if ( v != -1 ):
            if ( color[v] == 0 ):
                color[v] = 1
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            color[u] = 2
            tt += 1
            f[u] = tt
         dfs_visit
N = input()
color = [0] * N
d = [0] * N
f = [0] * N
nt = [0] * N
m = [[0] * N for i in range(N)]
S = []
tt = 0

def next(u):
    global nt
    w = nt[u]
    for v in range(w, N):
        nt[u] = v + 1
        if( m[u][v] ):
            return v
    return -1

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

    while( len(S) != 0 ):
        u = S[-1]

        v = next(u)
        if ( v != -1 ):
            if ( color[v] == 0 ):
                color[v] = 1
                tt += 1
                d[v] = tt
                S.append(v)
        else:
            S.pop()
            color[u] = 2
            tt += 1
            f[u] = tt
        
def dfs():
    global color
    for u in range(N):
        if( color[u] == 0 ):
            dfs_visit(u)

if __name__ == '__main__':

    for i in range(N):
        v = map(int, raw_input().split())
        for j in v[2:]:
            m[i][j-1] = 1
    
    dfs()

    for i in range(N):
        print (i+1), d[i], f[i]