def dfs(i,cnt):
    d[i] = cnt
    cnt += 1
    for j in edge[i]:
        if d[j] == -1:
            cnt = dfs(j,cnt)
    f[i] = cnt
    cnt += 1
    return cnt

n = int(input())
edge = [[] for i in range(n)]
for not_used in range(n):
    of_children, not_used, *v = map(lambda x: int(x)-1,input().split())
    edge[of_children] = sorted(v)
c = 1
d = [-1]*n
f = [-1]*n

for i in range(n):
    if d[i] == -1:
        c = dfs(i,c)
for i ,(d,f) in enumerate(zip(d,f)):
    print(i+1,d,f) def dfs(i,cnt):
    d[i] = cnt
    cnt += 1
    for j in edge[i]:
        if d[j] == -1:
            cnt = dfs(j,cnt)
    f[i] = cnt
    cnt += 1
    return cnt dfs d[i] = cnt d[i] d i cnt cnt += 1 cnt 1 for j in edge[i]:
        if d[j] == -1:
            cnt = dfs(j,cnt)
     j edge[i] edge i if d[j] == -1:
            cnt = dfs(j,cnt)
     d[j] == -1 d[j] d j -1 cnt = dfs(j,cnt) cnt dfs(j,cnt) dfs j cnt f[i] = cnt f[i] f i cnt cnt += 1 cnt 1 return cnt cnt i i cnt cnt 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) [] edge = [[] for i in range(n)] edge [[] for i in range(n)] for not_used in range(n):
    of_children, not_used, *v = map(lambda x: int(x)-1,input().split())
    edge[of_children] = sorted(v) not_used range(n) range n of_children, not_used, *v = map(lambda x: int(x)-1,input().split()) of_children map(lambda x: int(x)-1,input().split()) map lambda x: int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split not_used *v v edge[of_children] = sorted(v) edge[of_children] edge of_children sorted(v) sorted v c = 1 c 1 d = [-1]*n d [-1]*n [-1] -1 n f = [-1]*n f [-1]*n [-1] -1 n for i in range(n):
    if d[i] == -1:
        c = dfs(i,c) i range(n) range n if d[i] == -1:
        c = dfs(i,c) d[i] == -1 d[i] d i -1 c = dfs(i,c) c dfs(i,c) dfs i c for i ,(d,f) in enumerate(zip(d,f)):
    print(i+1,d,f) i (d,f) d f enumerate(zip(d,f)) enumerate zip(d,f) zip d f print(i+1,d,f) print i+1 i 1 d f edge = [[] for i in range(n)] [[] for i in range(n)] edge c = 1 1 c f = [-1]*n [-1]*n f of_children, not_used, *v = map(lambda x: int(x)-1,input().split()) map(lambda x: int(x)-1,input().split()) of_children d = [-1]*n [-1]*n d n = int(input()) int(input()) n not_used, *v = map(lambda x: int(x)-1,input().split()) map(lambda x: int(x)-1,input().split()) not_used c = dfs(i,c) dfs(i,c) c def dfs(i,cnt):
    d[i] = cnt
    cnt += 1
    for j in edge[i]:
        if d[j] == -1:
            cnt = dfs(j,cnt)
    f[i] = cnt
    cnt += 1
    return cnt def dfs(i,cnt):
    d[i] = cnt
    cnt += 1
    for j in edge[i]:
        if d[j] == -1:
            cnt = dfs(j,cnt)
    f[i] = cnt
    cnt += 1
    return cnt dfs
def dfs(i,cnt):
    d[i] = cnt
    cnt += 1
    for j in edge[i]:
        if d[j] == -1:
            cnt = dfs(j,cnt)
    f[i] = cnt
    cnt += 1
    return cnt

n = int(input())
edge = [[] for i in range(n)]
for not_used in range(n):
    of_children, not_used, *v = map(lambda x: int(x)-1,input().split())
    edge[of_children] = sorted(v)
c = 1
d = [-1]*n
f = [-1]*n

for i in range(n):
    if d[i] == -1:
        c = dfs(i,c)
for i ,(d,f) in enumerate(zip(d,f)):
    print(i+1,d,f)
