n = int(raw_input())

def dfs(u,t):
    global graph
    global found
    global timestamp

    if u in found: return t
    found.add(u)
    timestamp[u] = [-1,-1]
    timestamp[u][0] = t
    t += 1
    for v in graph[u]:
        t = dfs(v,t)
    timestamp[u][1] = t
    t += 1
    return t

graph = [[] for i in range(n)]
found = set()
timestamp = {}

for i in range(n):
    entry = map(int,raw_input().strip().split(' '))
    u = entry[0]
    u -= 1
    for v in entry[2:]:
        v -= 1
        graph[u].append(v)


t = 1
for i in range(n):
    t = dfs(i,t)

for i in timestamp:
    print i+1,timestamp[i][0],timestamp[i][1] n = int(raw_input()) n int(raw_input()) int raw_input() raw_input def dfs(u,t):
    global graph
    global found
    global timestamp

    if u in found: return t
    found.add(u)
    timestamp[u] = [-1,-1]
    timestamp[u][0] = t
    t += 1
    for v in graph[u]:
        t = dfs(v,t)
    timestamp[u][1] = t
    t += 1
    return t dfs global graph global found global timestamp if u in found: return t
     u in found u found found.add(u) found.add found add u timestamp[u] = [-1,-1] timestamp[u] timestamp u [-1,-1] -1 -1 timestamp[u][0] = t timestamp[u][0] [u] timestamp u 0 t t += 1 t 1 for v in graph[u]:
        t = dfs(v,t)
     v graph[u] graph u t = dfs(v,t) t dfs(v,t) dfs v t timestamp[u][1] = t timestamp[u][1] [u] timestamp u 1 t t += 1 t 1 return t t u u t t [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] graph = [[] for i in range(n)] graph [[] for i in range(n)] found = set() found set() set timestamp = {} timestamp {} for i in range(n):
    entry = map(int,raw_input().strip().split(' '))
    u = entry[0]
    u -= 1
    for v in entry[2:]:
        v -= 1
        graph[u].append(v) i range(n) range n entry = map(int,raw_input().strip().split(' ')) entry map(int,raw_input().strip().split(' ')) map int raw_input().strip().split(' ') ().strip().split ().strip() ().strip () raw_input strip split ' ' u = entry[0] u entry[0] entry 0 u -= 1 u 1 for v in entry[2:]:
        v -= 1
        graph[u].append(v) v entry[2:] entry 2: 2 v -= 1 v 1 graph[u].append(v) [u].append [u] graph u append v t = 1 t 1 for i in range(n):
    t = dfs(i,t) i range(n) range n t = dfs(i,t) t dfs(i,t) dfs i t for i in timestamp:
    print i+1,timestamp[i][0],timestamp[i][1] i timestamp print i+1 i 1 timestamp[i][0] [i] timestamp i 0 timestamp[i][1] [i] timestamp i 1 timestamp = {} {} timestamp n = int(raw_input()) int(raw_input()) n graph = [[] for i in range(n)] [[] for i in range(n)] graph u -= 1 1 u entry = map(int,raw_input().strip().split(' ')) map(int,raw_input().strip().split(' ')) entry found = set() set() found v -= 1 1 v t = dfs(i,t) dfs(i,t) t t = 1 1 t u = entry[0] entry[0] u def dfs(u,t):
    global graph
    global found
    global timestamp

    if u in found: return t
    found.add(u)
    timestamp[u] = [-1,-1]
    timestamp[u][0] = t
    t += 1
    for v in graph[u]:
        t = dfs(v,t)
    timestamp[u][1] = t
    t += 1
    return t def dfs(u,t):
    global graph
    global found
    global timestamp

    if u in found: return t
    found.add(u)
    timestamp[u] = [-1,-1]
    timestamp[u][0] = t
    t += 1
    for v in graph[u]:
        t = dfs(v,t)
    timestamp[u][1] = t
    t += 1
    return t dfs
n = int(raw_input())

def dfs(u,t):
    global graph
    global found
    global timestamp

    if u in found: return t
    found.add(u)
    timestamp[u] = [-1,-1]
    timestamp[u][0] = t
    t += 1
    for v in graph[u]:
        t = dfs(v,t)
    timestamp[u][1] = t
    t += 1
    return t

graph = [[] for i in range(n)]
found = set()
timestamp = {}

for i in range(n):
    entry = map(int,raw_input().strip().split(' '))
    u = entry[0]
    u -= 1
    for v in entry[2:]:
        v -= 1
        graph[u].append(v)


t = 1
for i in range(n):
    t = dfs(i,t)

for i in timestamp:
    print i+1,timestamp[i][0],timestamp[i][1]