n = int(input())
G = []
checked = [False for i in range(n + 1)]
d = [0 for i in range(n + 1)]
f = [0 for i in range(n + 1)]
G.append([])
for i in range(n):
    u, k, *v = map(int, input().split())
    G.append(v)

timestamp = 1

def dfs(id):
    global timestamp

    checked[id] = True
    d[id] = timestamp
    timestamp += 1
    for v in G[id]:
        if not checked[v]:
            dfs(v)
    f[id] = timestamp
    timestamp += 1

for id in range(1, n + 1):
    if not checked[id]:
        dfs(id)

for i in range(1, n + 1):
    print("{0} {1} {2}".format(i, d[i], f[i])) n = int(input()) n int(input()) int input() input G = [] G [] False 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) False checked = [False for i in range(n + 1)] checked [False for i in range(n + 1)] 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) 0 d = [0 for i in range(n + 1)] d [0 for i in range(n + 1)] 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) 0 f = [0 for i in range(n + 1)] f [0 for i in range(n + 1)] G.append([]) G.append G append [] for i in range(n):
    u, k, *v = map(int, input().split())
    G.append(v) i 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.append(v) G.append G append v timestamp = 1 timestamp 1 def dfs(id):
    global timestamp

    checked[id] = True
    d[id] = timestamp
    timestamp += 1
    for v in G[id]:
        if not checked[v]:
            dfs(v)
    f[id] = timestamp
    timestamp += 1 dfs global timestamp checked[id] = True checked[id] checked id True d[id] = timestamp d[id] d id timestamp timestamp += 1 timestamp 1 for v in G[id]:
        if not checked[v]:
            dfs(v)
     v G[id] G id if not checked[v]:
            dfs(v)
     not checked[v] checked[v] checked v dfs(v) dfs v f[id] = timestamp f[id] f id timestamp timestamp += 1 timestamp 1 id id for id in range(1, n + 1):
    if not checked[id]:
        dfs(id) id range(1, n + 1) range 1 n + 1 n 1 if not checked[id]:
        dfs(id) not checked[id] checked[id] checked id dfs(id) dfs id for i in range(1, n + 1):
    print("{0} {1} {2}".format(i, d[i], f[i])) i range(1, n + 1) range 1 n + 1 n 1 print("{0} {1} {2}".format(i, d[i], f[i])) print "{0} {1} {2}".format(i, d[i], f[i]) "{0} {1} {2}".format "{0} {1} {2}" format i d[i] d i f[i] f i f = [0 for i in range(n + 1)] [0 for i in range(n + 1)] f d = [0 for i in range(n + 1)] [0 for i in range(n + 1)] d timestamp = 1 1 timestamp u, k, *v = map(int, input().split()) map(int, input().split()) u def dfs(id):
    global timestamp

    checked[id] = True
    d[id] = timestamp
    timestamp += 1
    for v in G[id]:
        if not checked[v]:
            dfs(v)
    f[id] = timestamp
    timestamp += 1 def dfs(id):
    global timestamp

    checked[id] = True
    d[id] = timestamp
    timestamp += 1
    for v in G[id]:
        if not checked[v]:
            dfs(v)
    f[id] = timestamp
    timestamp += 1 dfs checked = [False for i in range(n + 1)] [False for i in range(n + 1)] checked n = int(input()) int(input()) n G = [] [] G k, *v = map(int, input().split()) map(int, input().split()) k
n = int(input())
G = []
checked = [False for i in range(n + 1)]
d = [0 for i in range(n + 1)]
f = [0 for i in range(n + 1)]
G.append([])
for i in range(n):
    u, k, *v = map(int, input().split())
    G.append(v)

timestamp = 1

def dfs(id):
    global timestamp

    checked[id] = True
    d[id] = timestamp
    timestamp += 1
    for v in G[id]:
        if not checked[v]:
            dfs(v)
    f[id] = timestamp
    timestamp += 1

for id in range(1, n + 1):
    if not checked[id]:
        dfs(id)

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