import sys
sys.setrecursionlimit(10000000)
n = int(input())
G = [[] for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
color = [0 for i in range(n)]
stamp = 0

def dfs(u):
    global stamp
    if d[u]:
        return
    stamp += 1
    d[u] = stamp
    for v in G[u]:
        if color[v] != 0:
            continue
        color[v] = 1
        dfs(v)
    color[u] = 2
    stamp += 1
    f[u] = stamp

color[0] = 1
for i in range(n):
    inp = list(map(int, input().split()))
    u = inp[0]
    u -= 1
    k = inp[1]
    for j in range(k):
        v = inp[j+2]
        v -= 1
        G[u].append(v)
        #G[v].append(u)


for i in range(n):
    dfs(i)

for i in range(n):
    print("{0} {1} {2}".format(i+1, d[i], f[i])) import sys sys sys.setrecursionlimit(10000000) sys.setrecursionlimit sys setrecursionlimit 10000000 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) [] G = [[] for i in range(n)] G [[] for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 d = [0 for i in range(n)] d [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 f = [0 for i in range(n)] f [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 color = [0 for i in range(n)] color [0 for i in range(n)] stamp = 0 stamp 0 def dfs(u):
    global stamp
    if d[u]:
        return
    stamp += 1
    d[u] = stamp
    for v in G[u]:
        if color[v] != 0:
            continue
        color[v] = 1
        dfs(v)
    color[u] = 2
    stamp += 1
    f[u] = stamp dfs global stamp if d[u]:
        return
     d[u] d u return stamp += 1 stamp 1 d[u] = stamp d[u] d u stamp for v in G[u]:
        if color[v] != 0:
            continue
        color[v] = 1
        dfs(v)
     v G[u] G u if color[v] != 0:
            continue
         color[v] != 0 color[v] color v 0 continue color[v] = 1 color[v] color v 1 dfs(v) dfs v color[u] = 2 color[u] color u 2 stamp += 1 stamp 1 f[u] = stamp f[u] f u stamp u u color[0] = 1 color[0] color 0 1 for i in range(n):
    inp = list(map(int, input().split()))
    u = inp[0]
    u -= 1
    k = inp[1]
    for j in range(k):
        v = inp[j+2]
        v -= 1
        G[u].append(v)
        #G[v].append(u) i range(n) range n inp = list(map(int, input().split())) inp list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u = inp[0] u inp[0] inp 0 u -= 1 u 1 k = inp[1] k inp[1] inp 1 for j in range(k):
        v = inp[j+2]
        v -= 1
        G[u].append(v)
        #G[v].append(u) j range(k) range k v = inp[j+2] v inp[j+2] inp j+2 j 2 v -= 1 v 1 G[u].append(v) [u].append [u] G u append v for i in range(n):
    dfs(i) i range(n) range n dfs(i) dfs i for i in range(n):
    print("{0} {1} {2}".format(i+1, d[i], f[i])) i range(n) range n print("{0} {1} {2}".format(i+1, d[i], f[i])) print "{0} {1} {2}".format(i+1, d[i], f[i]) "{0} {1} {2}".format "{0} {1} {2}" format i+1 i 1 d[i] d i f[i] f i G = [[] for i in range(n)] [[] for i in range(n)] G color = [0 for i in range(n)] [0 for i in range(n)] color f = [0 for i in range(n)] [0 for i in range(n)] f u = inp[0] inp[0] u k = inp[1] inp[1] k n = int(input()) int(input()) n u -= 1 1 u inp = list(map(int, input().split())) list(map(int, input().split())) inp stamp = 0 0 stamp v -= 1 1 v v = inp[j+2] inp[j+2] v def dfs(u):
    global stamp
    if d[u]:
        return
    stamp += 1
    d[u] = stamp
    for v in G[u]:
        if color[v] != 0:
            continue
        color[v] = 1
        dfs(v)
    color[u] = 2
    stamp += 1
    f[u] = stamp def dfs(u):
    global stamp
    if d[u]:
        return
    stamp += 1
    d[u] = stamp
    for v in G[u]:
        if color[v] != 0:
            continue
        color[v] = 1
        dfs(v)
    color[u] = 2
    stamp += 1
    f[u] = stamp dfs d = [0 for i in range(n)] [0 for i in range(n)] d
import sys
sys.setrecursionlimit(10000000)
n = int(input())
G = [[] for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
color = [0 for i in range(n)]
stamp = 0

def dfs(u):
    global stamp
    if d[u]:
        return
    stamp += 1
    d[u] = stamp
    for v in G[u]:
        if color[v] != 0:
            continue
        color[v] = 1
        dfs(v)
    color[u] = 2
    stamp += 1
    f[u] = stamp

color[0] = 1
for i in range(n):
    inp = list(map(int, input().split()))
    u = inp[0]
    u -= 1
    k = inp[1]
    for j in range(k):
        v = inp[j+2]
        v -= 1
        G[u].append(v)
        #G[v].append(u)


for i in range(n):
    dfs(i)

for i in range(n):
    print("{0} {1} {2}".format(i+1, d[i], f[i]))
