n = int(input())
graph = [-1] + [list(map(int, input().split())) for _ in range(n)]
seen = [False]*(n+1)
seen[0] = True
d = [-1]*(n+1)
f = [-1]*(n+1)
time = 0


def dfs(v):
    global time
    time += 1
    d[v] = time
    seen[v] = True
    k = graph[v][1]
    if k > 0:
        for i in range(k):
            w = graph[v][i+2]
            if seen[w] is False:
                dfs(w)
    
    time += 1
    f[v] = time

v = 0
while v <= n:
    if seen[v] is False:
        dfs(v)
    
    v += 1

for i in range(1, n+1):
    print(i, d[i], f[i]) n = int(input()) n int(input()) int input() input list(map(int, input().split())) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split graph = [-1] + [list(map(int, input().split())) for _ in range(n)] graph [-1] + [list(map(int, input().split())) for _ in range(n)] [-1] -1 [list(map(int, input().split())) for _ in range(n)] seen = [False]*(n+1) seen [False]*(n+1) [False] False n+1 n 1 seen[0] = True seen[0] seen 0 True d = [-1]*(n+1) d [-1]*(n+1) [-1] -1 n+1 n 1 f = [-1]*(n+1) f [-1]*(n+1) [-1] -1 n+1 n 1 time = 0 time 0 def dfs(v):
    global time
    time += 1
    d[v] = time
    seen[v] = True
    k = graph[v][1]
    if k > 0:
        for i in range(k):
            w = graph[v][i+2]
            if seen[w] is False:
                dfs(w)
    
    time += 1
    f[v] = time dfs global time time += 1 time 1 d[v] = time d[v] d v time seen[v] = True seen[v] seen v True k = graph[v][1] k graph[v][1] [v] graph v 1 if k > 0:
        for i in range(k):
            w = graph[v][i+2]
            if seen[w] is False:
                dfs(w)
    
     k > 0 k 0 for i in range(k):
            w = graph[v][i+2]
            if seen[w] is False:
                dfs(w)
    
     i range(k) range k w = graph[v][i+2] w graph[v][i+2] [v] graph v i+2 i 2 if seen[w] is False:
                dfs(w)
    
     seen[w] is False seen[w] seen w False dfs(w) dfs w time += 1 time 1 f[v] = time f[v] f v time v v v = 0 v 0 while v <= n:
    if seen[v] is False:
        dfs(v)
    
    v += 1 v <= n v n if seen[v] is False:
        dfs(v)
    
     seen[v] is False seen[v] seen v False dfs(v) dfs v v += 1 v 1 for i in range(1, n+1):
    print(i, d[i], f[i]) i range(1, n+1) range 1 n+1 n 1 print(i, d[i], f[i]) print i d[i] d i f[i] f i d = [-1]*(n+1) [-1]*(n+1) d seen = [False]*(n+1) [False]*(n+1) seen n = int(input()) int(input()) n def dfs(v):
    global time
    time += 1
    d[v] = time
    seen[v] = True
    k = graph[v][1]
    if k > 0:
        for i in range(k):
            w = graph[v][i+2]
            if seen[w] is False:
                dfs(w)
    
    time += 1
    f[v] = time def dfs(v):
    global time
    time += 1
    d[v] = time
    seen[v] = True
    k = graph[v][1]
    if k > 0:
        for i in range(k):
            w = graph[v][i+2]
            if seen[w] is False:
                dfs(w)
    
    time += 1
    f[v] = time dfs v = 0 0 v time = 0 0 time f = [-1]*(n+1) [-1]*(n+1) f graph = [-1] + [list(map(int, input().split())) for _ in range(n)] [-1] + [list(map(int, input().split())) for _ in range(n)] graph v += 1 1 v
n = int(input())
graph = [-1] + [list(map(int, input().split())) for _ in range(n)]
seen = [False]*(n+1)
seen[0] = True
d = [-1]*(n+1)
f = [-1]*(n+1)
time = 0


def dfs(v):
    global time
    time += 1
    d[v] = time
    seen[v] = True
    k = graph[v][1]
    if k > 0:
        for i in range(k):
            w = graph[v][i+2]
            if seen[w] is False:
                dfs(w)
    
    time += 1
    f[v] = time

v = 0
while v <= n:
    if seen[v] is False:
        dfs(v)
    
    v += 1

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