def MAIN():
    n = int(input())
    ans = [[i, 0, 0] for i in range((n + 1))]
    G = [[] for _ in range((n + 1))]
    for _ in range(n):
        u, k, *v = map(int, input().split())
        G[u] = v
    cnt = 1
    def dfs(u):
        nonlocal ans
        if ans[u][1] != 0:
            return
        nonlocal cnt
        ans[u][1] = cnt
        cnt += 1
        for v in G[u]:
            dfs(v)
        ans[u][2] = cnt
        cnt += 1
    for i in range(1, n + 1):
        if ans[i][1] == 0:
            dfs(i)
        print(*ans[i])
MAIN()
 def MAIN():
    n = int(input())
    ans = [[i, 0, 0] for i in range((n + 1))]
    G = [[] for _ in range((n + 1))]
    for _ in range(n):
        u, k, *v = map(int, input().split())
        G[u] = v
    cnt = 1
    def dfs(u):
        nonlocal ans
        if ans[u][1] != 0:
            return
        nonlocal cnt
        ans[u][1] = cnt
        cnt += 1
        for v in G[u]:
            dfs(v)
        ans[u][2] = cnt
        cnt += 1
    for i in range(1, n + 1):
        if ans[i][1] == 0:
            dfs(i)
        print(*ans[i]) MAIN n = int(input()) n int(input()) int input() input [i, 0, 0] for i in range((n + 1)) for i in range((n + 1)) i range((n + 1)) range n + 1 n 1 for i in range((n + 1)) [i, 0, 0] i 0 0 ans = [[i, 0, 0] for i in range((n + 1))] ans [[i, 0, 0] for i in range((n + 1))] [] for _ in range((n + 1)) for _ in range((n + 1)) _ range((n + 1)) range n + 1 n 1 for _ in range((n + 1)) [] G = [[] for _ in range((n + 1))] G [[] for _ in range((n + 1))] for _ in range(n):
        u, k, *v = map(int, input().split())
        G[u] = v
     _ range(n) range n u, k, *v = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split k *v v G[u] = v G[u] G u v cnt = 1 cnt 1 def dfs(u):
        nonlocal ans
        if ans[u][1] != 0:
            return
        nonlocal cnt
        ans[u][1] = cnt
        cnt += 1
        for v in G[u]:
            dfs(v)
        ans[u][2] = cnt
        cnt += 1
     dfs nonlocal ans if ans[u][1] != 0:
            return
         ans[u][1] != 0 ans[u][1] [u] ans u 1 0 return nonlocal cnt ans[u][1] = cnt ans[u][1] [u] ans u 1 cnt cnt += 1 cnt 1 for v in G[u]:
            dfs(v)
         v G[u] G u dfs(v) dfs v ans[u][2] = cnt ans[u][2] [u] ans u 2 cnt cnt += 1 cnt 1 u u for i in range(1, n + 1):
        if ans[i][1] == 0:
            dfs(i)
        print(*ans[i]) i range(1, n + 1) range 1 n + 1 n 1 if ans[i][1] == 0:
            dfs(i)
         ans[i][1] == 0 ans[i][1] [i] ans i 1 0 dfs(i) dfs i print(*ans[i]) print *ans[i] ans[i] ans i MAIN() MAIN def MAIN():
    n = int(input())
    ans = [[i, 0, 0] for i in range((n + 1))]
    G = [[] for _ in range((n + 1))]
    for _ in range(n):
        u, k, *v = map(int, input().split())
        G[u] = v
    cnt = 1
    def dfs(u):
        nonlocal ans
        if ans[u][1] != 0:
            return
        nonlocal cnt
        ans[u][1] = cnt
        cnt += 1
        for v in G[u]:
            dfs(v)
        ans[u][2] = cnt
        cnt += 1
    for i in range(1, n + 1):
        if ans[i][1] == 0:
            dfs(i)
        print(*ans[i]) def MAIN():
    n = int(input())
    ans = [[i, 0, 0] for i in range((n + 1))]
    G = [[] for _ in range((n + 1))]
    for _ in range(n):
        u, k, *v = map(int, input().split())
        G[u] = v
    cnt = 1
    def dfs(u):
        nonlocal ans
        if ans[u][1] != 0:
            return
        nonlocal cnt
        ans[u][1] = cnt
        cnt += 1
        for v in G[u]:
            dfs(v)
        ans[u][2] = cnt
        cnt += 1
    for i in range(1, n + 1):
        if ans[i][1] == 0:
            dfs(i)
        print(*ans[i]) MAIN
def MAIN():
    n = int(input())
    ans = [[i, 0, 0] for i in range((n + 1))]
    G = [[] for _ in range((n + 1))]
    for _ in range(n):
        u, k, *v = map(int, input().split())
        G[u] = v
    cnt = 1
    def dfs(u):
        nonlocal ans
        if ans[u][1] != 0:
            return
        nonlocal cnt
        ans[u][1] = cnt
        cnt += 1
        for v in G[u]:
            dfs(v)
        ans[u][2] = cnt
        cnt += 1
    for i in range(1, n + 1):
        if ans[i][1] == 0:
            dfs(i)
        print(*ans[i])
MAIN()

