# -*- coding: utf-8 -*-


if __name__ == '__main__':

    n = int(input())
    M = [[0 for i in range(n)] for j in range(n)]
    for _ in range(n):
        l = list(map(int, input().split(" ")))
        u = l[0]
        k = l[1]
        if k != 0:
            for v in l[2:]:
                M[u-1][v-1] = 1
    
    color = [0]*n
    d = [0]*n
    f = [0]*n
    time = 0
    
    def dfs(u): #depth-first search
        global time
        color[u] = 1
        time += 1
        d[u] = time
        for v in range(n):
            if M[u][v] == 1 and color[v] == 0:
                dfs(v)
        color[u] = 2
        time += 1
        f[u] = time
    
    for u in range(n):
        if color[u] == 0:
            dfs(u)

    for u in range(n):
        print(u+1, d[u], f[u])
 if __name__ == '__main__':

    n = int(input())
    M = [[0 for i in range(n)] for j in range(n)]
    for _ in range(n):
        l = list(map(int, input().split(" ")))
        u = l[0]
        k = l[1]
        if k != 0:
            for v in l[2:]:
                M[u-1][v-1] = 1
    
    color = [0]*n
    d = [0]*n
    f = [0]*n
    time = 0
    
    def dfs(u): #depth-first search
        global time
        color[u] = 1
        time += 1
        d[u] = time
        for v in range(n):
            if M[u][v] == 1 and color[v] == 0:
                dfs(v)
        color[u] = 2
        time += 1
        f[u] = time
    
    for u in range(n):
        if color[u] == 0:
            dfs(u)

    for u in range(n):
        print(u+1, d[u], f[u]) __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input [0 for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] M [[0 for i in range(n)] for j in range(n)] for _ in range(n):
        l = list(map(int, input().split(" ")))
        u = l[0]
        k = l[1]
        if k != 0:
            for v in l[2:]:
                M[u-1][v-1] = 1
    
     _ range(n) range n l = list(map(int, input().split(" "))) l list(map(int, input().split(" "))) list map(int, input().split(" ")) map int input().split(" ") ().split () input split " " u = l[0] u l[0] l 0 k = l[1] k l[1] l 1 if k != 0:
            for v in l[2:]:
                M[u-1][v-1] = 1
    
     k != 0 k 0 for v in l[2:]:
                M[u-1][v-1] = 1
    
     v l[2:] l 2: 2 M[u-1][v-1] = 1 M[u-1][v-1] [u-1] M u-1 u 1 v-1 v 1 1 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 time = 0 time 0 def dfs(u): #depth-first search
        global time
        color[u] = 1
        time += 1
        d[u] = time
        for v in range(n):
            if M[u][v] == 1 and color[v] == 0:
                dfs(v)
        color[u] = 2
        time += 1
        f[u] = time
    
     dfs global time color[u] = 1 color[u] color u 1 time += 1 time 1 d[u] = time d[u] d u time for v in range(n):
            if M[u][v] == 1 and color[v] == 0:
                dfs(v)
         v range(n) range n if M[u][v] == 1 and color[v] == 0:
                dfs(v)
         M[u][v] == 1 and color[v] == 0 M[u][v] == 1 M[u][v] [u] M u v 1 color[v] == 0 color[v] color v 0 dfs(v) dfs v color[u] = 2 color[u] color u 2 time += 1 time 1 f[u] = time f[u] f u time u u for u in range(n):
        if color[u] == 0:
            dfs(u)

     u range(n) range n if color[u] == 0:
            dfs(u)

     color[u] == 0 color[u] color u 0 dfs(u) dfs u for u in range(n):
        print(u+1, d[u], f[u]) u range(n) range n print(u+1, d[u], f[u]) print u+1 u 1 d[u] d u f[u] f u color = [0]*n [0]*n color f = [0]*n [0]*n f time = 0 0 time def dfs(u): #depth-first search
        global time
        color[u] = 1
        time += 1
        d[u] = time
        for v in range(n):
            if M[u][v] == 1 and color[v] == 0:
                dfs(v)
        color[u] = 2
        time += 1
        f[u] = time
    
     def dfs(u): #depth-first search
        global time
        color[u] = 1
        time += 1
        d[u] = time
        for v in range(n):
            if M[u][v] == 1 and color[v] == 0:
                dfs(v)
        color[u] = 2
        time += 1
        f[u] = time
    
     dfs k = l[1] l[1] k M = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] M d = [0]*n [0]*n d u = l[0] l[0] u n = int(input()) int(input()) n l = list(map(int, input().split(" "))) list(map(int, input().split(" "))) l
# -*- coding: utf-8 -*-


if __name__ == '__main__':

    n = int(input())
    M = [[0 for i in range(n)] for j in range(n)]
    for _ in range(n):
        l = list(map(int, input().split(" ")))
        u = l[0]
        k = l[1]
        if k != 0:
            for v in l[2:]:
                M[u-1][v-1] = 1
    
    color = [0]*n
    d = [0]*n
    f = [0]*n
    time = 0
    
    def dfs(u): #depth-first search
        global time
        color[u] = 1
        time += 1
        d[u] = time
        for v in range(n):
            if M[u][v] == 1 and color[v] == 0:
                dfs(v)
        color[u] = 2
        time += 1
        f[u] = time
    
    for u in range(n):
        if color[u] == 0:
            dfs(u)

    for u in range(n):
        print(u+1, d[u], f[u])

