n = int(input())
d = [0]*n
f = [0]*n
G = [[] for _ in range(n)]
for _ in range(n):
    l = list(map(int, input().split()))
    u, k = l[:2]
    l = list(map(lambda x: x-1, l[2:]))
    G[u-1] = l

timestamp = [i+1 for i in range(2*n)]
def dfs(node):
    global d,f,G,timestamp
    if d[node]>0:
        return False
    d[node] = timestamp.pop(0)
    for v in G[node]:
        dfs(v)
    if f[node]==0:
        f[node] = timestamp.pop(0)
    return True
for i in range(n):
    dfs(i)
    
for i in range(n):
    print(i+1, d[i], f[i]) n = int(input()) n int(input()) int input() input d = [0]*n d [0]*n [0] 0 n f = [0]*n f [0]*n [0] 0 n [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] G = [[] for _ in range(n)] G [[] for _ in range(n)] for _ in range(n):
    l = list(map(int, input().split()))
    u, k = l[:2]
    l = list(map(lambda x: x-1, l[2:]))
    G[u-1] = l _ range(n) range n l = list(map(int, input().split())) l list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u, k = l[:2] u l[:2] l :2 2 k l = list(map(lambda x: x-1, l[2:])) l list(map(lambda x: x-1, l[2:])) list map(lambda x: x-1, l[2:]) map lambda x: x-1 x-1 x 1 x l[2:] l 2: 2 G[u-1] = l G[u-1] G u-1 u 1 l i+1 for i in range(2*n) for i in range(2*n) i range(2*n) range 2*n 2 n for i in range(2*n) i+1 i 1 timestamp = [i+1 for i in range(2*n)] timestamp [i+1 for i in range(2*n)] def dfs(node):
    global d,f,G,timestamp
    if d[node]>0:
        return False
    d[node] = timestamp.pop(0)
    for v in G[node]:
        dfs(v)
    if f[node]==0:
        f[node] = timestamp.pop(0)
    return True dfs global d,f,G,timestamp if d[node]>0:
        return False
     d[node]>0 d[node] d node 0 return False False d[node] = timestamp.pop(0) d[node] d node timestamp.pop(0) timestamp.pop timestamp pop 0 for v in G[node]:
        dfs(v)
     v G[node] G node dfs(v) dfs v if f[node]==0:
        f[node] = timestamp.pop(0)
     f[node]==0 f[node] f node 0 f[node] = timestamp.pop(0) f[node] f node timestamp.pop(0) timestamp.pop timestamp pop 0 return True True node node for i in range(n):
    dfs(i)
     i range(n) range n 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 l = list(map(int, input().split())) list(map(int, input().split())) l timestamp = [i+1 for i in range(2*n)] [i+1 for i in range(2*n)] timestamp f = [0]*n [0]*n f d = [0]*n [0]*n d G = [[] for _ in range(n)] [[] for _ in range(n)] G u, k = l[:2] l[:2] u l = list(map(lambda x: x-1, l[2:])) list(map(lambda x: x-1, l[2:])) l n = int(input()) int(input()) n k = l[:2] l[:2] k def dfs(node):
    global d,f,G,timestamp
    if d[node]>0:
        return False
    d[node] = timestamp.pop(0)
    for v in G[node]:
        dfs(v)
    if f[node]==0:
        f[node] = timestamp.pop(0)
    return True def dfs(node):
    global d,f,G,timestamp
    if d[node]>0:
        return False
    d[node] = timestamp.pop(0)
    for v in G[node]:
        dfs(v)
    if f[node]==0:
        f[node] = timestamp.pop(0)
    return True dfs
n = int(input())
d = [0]*n
f = [0]*n
G = [[] for _ in range(n)]
for _ in range(n):
    l = list(map(int, input().split()))
    u, k = l[:2]
    l = list(map(lambda x: x-1, l[2:]))
    G[u-1] = l

timestamp = [i+1 for i in range(2*n)]
def dfs(node):
    global d,f,G,timestamp
    if d[node]>0:
        return False
    d[node] = timestamp.pop(0)
    for v in G[node]:
        dfs(v)
    if f[node]==0:
        f[node] = timestamp.pop(0)
    return True
for i in range(n):
    dfs(i)
    
for i in range(n):
    print(i+1, d[i], f[i])
