def dfs(v, time_, d, f, dp):
    if d[v] == 0:
        d[v] = time_
    for i in range(len(dp[v])):
        if d[dp[v][i]] == 0:
            time_ = dfs(dp[v][i], time_ + 1, d, f, dp)
    f[v] = time_ + 1
    return time_ +  1


def main():
    N = int(input())
    dp = [[] for i in range(N)]
    for i in range(N):
        line = [int(k) for k in input().split()]
        for j in range(len(line)):
            if j == 0 or j == 1:
                continue
            dp[line[0] - 1].append(line[j] - 1)

    d = [0] * N
    f = [0] * N
    time_ = 1
    for i in range(N):
        if d[i] == 0:
            time_ = dfs(i, time_, d, f, dp)
            time_ += 1
    for i in range(N):
        print(i + 1, d[i], f[i])

if __name__ == '__main__':
    main()
 def dfs(v, time_, d, f, dp):
    if d[v] == 0:
        d[v] = time_
    for i in range(len(dp[v])):
        if d[dp[v][i]] == 0:
            time_ = dfs(dp[v][i], time_ + 1, d, f, dp)
    f[v] = time_ + 1
    return time_ +  1 dfs if d[v] == 0:
        d[v] = time_
     d[v] == 0 d[v] d v 0 d[v] = time_ d[v] d v time_ for i in range(len(dp[v])):
        if d[dp[v][i]] == 0:
            time_ = dfs(dp[v][i], time_ + 1, d, f, dp)
     i range(len(dp[v])) range len(dp[v]) len dp[v] dp v if d[dp[v][i]] == 0:
            time_ = dfs(dp[v][i], time_ + 1, d, f, dp)
     d[dp[v][i]] == 0 d[dp[v][i]] d dp[v][i] [v] dp v i 0 time_ = dfs(dp[v][i], time_ + 1, d, f, dp) time_ dfs(dp[v][i], time_ + 1, d, f, dp) dfs dp[v][i] [v] dp v i time_ + 1 time_ 1 d f dp f[v] = time_ + 1 f[v] f v time_ + 1 time_ 1 return time_ +  1 time_ +  1 time_ 1 v v time_ time_ d d f f dp dp def main():
    N = int(input())
    dp = [[] for i in range(N)]
    for i in range(N):
        line = [int(k) for k in input().split()]
        for j in range(len(line)):
            if j == 0 or j == 1:
                continue
            dp[line[0] - 1].append(line[j] - 1)

    d = [0] * N
    f = [0] * N
    time_ = 1
    for i in range(N):
        if d[i] == 0:
            time_ = dfs(i, time_, d, f, dp)
            time_ += 1
    for i in range(N):
        print(i + 1, d[i], f[i]) main N = int(input()) N int(input()) int input() input [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] dp = [[] for i in range(N)] dp [[] for i in range(N)] for i in range(N):
        line = [int(k) for k in input().split()]
        for j in range(len(line)):
            if j == 0 or j == 1:
                continue
            dp[line[0] - 1].append(line[j] - 1)

     i range(N) range N int(k) for k in input().split() for k in input().split() k input().split() ().split () input split for k in input().split() int(k) int k line = [int(k) for k in input().split()] line [int(k) for k in input().split()] for j in range(len(line)):
            if j == 0 or j == 1:
                continue
            dp[line[0] - 1].append(line[j] - 1)

     j range(len(line)) range len(line) len line if j == 0 or j == 1:
                continue
             j == 0 or j == 1 j == 0 j 0 j == 1 j 1 continue dp[line[0] - 1].append(line[j] - 1) [line[0] - 1].append [line[0] - 1] dp line[0] - 1 line[0] line 0 1 append line[j] - 1 line[j] line j 1 d = [0] * N d [0] * N [0] 0 N f = [0] * N f [0] * N [0] 0 N time_ = 1 time_ 1 for i in range(N):
        if d[i] == 0:
            time_ = dfs(i, time_, d, f, dp)
            time_ += 1
     i range(N) range N if d[i] == 0:
            time_ = dfs(i, time_, d, f, dp)
            time_ += 1
     d[i] == 0 d[i] d i 0 time_ = dfs(i, time_, d, f, dp) time_ dfs(i, time_, d, f, dp) dfs i time_ d f dp time_ += 1 time_ 1 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 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N = int(input())
    dp = [[] for i in range(N)]
    for i in range(N):
        line = [int(k) for k in input().split()]
        for j in range(len(line)):
            if j == 0 or j == 1:
                continue
            dp[line[0] - 1].append(line[j] - 1)

    d = [0] * N
    f = [0] * N
    time_ = 1
    for i in range(N):
        if d[i] == 0:
            time_ = dfs(i, time_, d, f, dp)
            time_ += 1
    for i in range(N):
        print(i + 1, d[i], f[i]) def main():
    N = int(input())
    dp = [[] for i in range(N)]
    for i in range(N):
        line = [int(k) for k in input().split()]
        for j in range(len(line)):
            if j == 0 or j == 1:
                continue
            dp[line[0] - 1].append(line[j] - 1)

    d = [0] * N
    f = [0] * N
    time_ = 1
    for i in range(N):
        if d[i] == 0:
            time_ = dfs(i, time_, d, f, dp)
            time_ += 1
    for i in range(N):
        print(i + 1, d[i], f[i]) main def dfs(v, time_, d, f, dp):
    if d[v] == 0:
        d[v] = time_
    for i in range(len(dp[v])):
        if d[dp[v][i]] == 0:
            time_ = dfs(dp[v][i], time_ + 1, d, f, dp)
    f[v] = time_ + 1
    return time_ +  1 def dfs(v, time_, d, f, dp):
    if d[v] == 0:
        d[v] = time_
    for i in range(len(dp[v])):
        if d[dp[v][i]] == 0:
            time_ = dfs(dp[v][i], time_ + 1, d, f, dp)
    f[v] = time_ + 1
    return time_ +  1 dfs
def dfs(v, time_, d, f, dp):
    if d[v] == 0:
        d[v] = time_
    for i in range(len(dp[v])):
        if d[dp[v][i]] == 0:
            time_ = dfs(dp[v][i], time_ + 1, d, f, dp)
    f[v] = time_ + 1
    return time_ +  1


def main():
    N = int(input())
    dp = [[] for i in range(N)]
    for i in range(N):
        line = [int(k) for k in input().split()]
        for j in range(len(line)):
            if j == 0 or j == 1:
                continue
            dp[line[0] - 1].append(line[j] - 1)

    d = [0] * N
    f = [0] * N
    time_ = 1
    for i in range(N):
        if d[i] == 0:
            time_ = dfs(i, time_, d, f, dp)
            time_ += 1
    for i in range(N):
        print(i + 1, d[i], f[i])

if __name__ == '__main__':
    main()

