import sys


def dfs(u):
    global time
    color[u] = "GRAY"
    time += 1
    d[u] = time
    for v in range(n):
        if M[u][v] and color[v] == "WHITE":
            dfs(v)
    color[u] = "BLACK"
    time += 1
    f[u] = time


if __name__ == "__main__":
    n = int(sys.stdin.readline())
    color = ["WHITE"] * n
    time = 0
    d = [-1] * n
    f = [-1] * n
    M = [[0] * n for i in range(n)]
    for inp in sys.stdin.readlines():
        inp = list(map(int, inp.split()))
        for i in inp[2:]:
            M[inp[0]-1][i-1] = 1
    for i in range(n):
        if d[i] == -1:
            dfs(i)
    for i in range(n):
        print(i+1, d[i], f[i]) import sys sys def dfs(u):
    global time
    color[u] = "GRAY"
    time += 1
    d[u] = time
    for v in range(n):
        if M[u][v] and color[v] == "WHITE":
            dfs(v)
    color[u] = "BLACK"
    time += 1
    f[u] = time dfs global time color[u] = "GRAY" color[u] color u "GRAY" time += 1 time 1 d[u] = time d[u] d u time for v in range(n):
        if M[u][v] and color[v] == "WHITE":
            dfs(v)
     v range(n) range n if M[u][v] and color[v] == "WHITE":
            dfs(v)
     M[u][v] and color[v] == "WHITE" M[u][v] [u] M u v color[v] == "WHITE" color[v] color v "WHITE" dfs(v) dfs v color[u] = "BLACK" color[u] color u "BLACK" time += 1 time 1 f[u] = time f[u] f u time u u if __name__ == "__main__":
    n = int(sys.stdin.readline())
    color = ["WHITE"] * n
    time = 0
    d = [-1] * n
    f = [-1] * n
    M = [[0] * n for i in range(n)]
    for inp in sys.stdin.readlines():
        inp = list(map(int, inp.split()))
        for i in inp[2:]:
            M[inp[0]-1][i-1] = 1
    for i in range(n):
        if d[i] == -1:
            dfs(i)
    for i in range(n):
        print(i+1, d[i], f[i]) __name__ == "__main__" __name__ "__main__" n = int(sys.stdin.readline()) n int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline color = ["WHITE"] * n color ["WHITE"] * n ["WHITE"] "WHITE" n time = 0 time 0 d = [-1] * n d [-1] * n [-1] -1 n f = [-1] * n f [-1] * n [-1] -1 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)] for inp in sys.stdin.readlines():
        inp = list(map(int, inp.split()))
        for i in inp[2:]:
            M[inp[0]-1][i-1] = 1
     inp sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines inp = list(map(int, inp.split())) inp list(map(int, inp.split())) list map(int, inp.split()) map int inp.split() inp.split inp split for i in inp[2:]:
            M[inp[0]-1][i-1] = 1
     i inp[2:] inp 2: 2 M[inp[0]-1][i-1] = 1 M[inp[0]-1][i-1] [inp[0]-1] M inp[0]-1 inp[0] inp 0 1 i-1 i 1 1 for i in range(n):
        if d[i] == -1:
            dfs(i)
     i range(n) range n if d[i] == -1:
            dfs(i)
     d[i] == -1 d[i] d i -1 dfs(i) dfs i for i in range(n):
        print(i+1, d[i], f[i]) i range(n) range n print(i+1, d[i], f[i]) print i+1 i 1 d[i] d i f[i] f i n = int(sys.stdin.readline()) int(sys.stdin.readline()) n d = [-1] * n [-1] * n d def dfs(u):
    global time
    color[u] = "GRAY"
    time += 1
    d[u] = time
    for v in range(n):
        if M[u][v] and color[v] == "WHITE":
            dfs(v)
    color[u] = "BLACK"
    time += 1
    f[u] = time def dfs(u):
    global time
    color[u] = "GRAY"
    time += 1
    d[u] = time
    for v in range(n):
        if M[u][v] and color[v] == "WHITE":
            dfs(v)
    color[u] = "BLACK"
    time += 1
    f[u] = time dfs time = 0 0 time color = ["WHITE"] * n ["WHITE"] * n color M = [[0] * n for i in range(n)] [[0] * n for i in range(n)] M inp = list(map(int, inp.split())) list(map(int, inp.split())) inp f = [-1] * n [-1] * n f
import sys


def dfs(u):
    global time
    color[u] = "GRAY"
    time += 1
    d[u] = time
    for v in range(n):
        if M[u][v] and color[v] == "WHITE":
            dfs(v)
    color[u] = "BLACK"
    time += 1
    f[u] = time


if __name__ == "__main__":
    n = int(sys.stdin.readline())
    color = ["WHITE"] * n
    time = 0
    d = [-1] * n
    f = [-1] * n
    M = [[0] * n for i in range(n)]
    for inp in sys.stdin.readlines():
        inp = list(map(int, inp.split()))
        for i in inp[2:]:
            M[inp[0]-1][i-1] = 1
    for i in range(n):
        if d[i] == -1:
            dfs(i)
    for i in range(n):
        print(i+1, d[i], f[i])