class Node:
    def __init__(self,v):
        self.v = v
        self.c = []

def dfs(n,f,d,t,visited):
    visited.add(n.v)
    f[n.v] = t
    t2 = t
    for c in sorted(n.c,key=lambda x:x.v):
        if not c.v in visited:
            t2 = dfs(c,f,d,t2+1,visited)
    d[n.v] = t2+1
    return t2+1

n = int(raw_input())
nodes = {}
for _ in range(n):
    entry = map(int,raw_input().split(' '))
    nid = entry[0]
    if not nid in nodes: nodes[nid] = Node(nid)
    k = entry[1]
    if k > 0:
        children = entry[2:]
        for c in children:
            if not c in nodes: nodes[c] = Node(c)
            nodes[nid].c.append(nodes[c])

f = {}
d = {}
visited = set()
t = dfs(nodes[1],f,d,1,visited)
while len(visited) < len(nodes):
    for nid in nodes:
        if not nid in visited:
            t = dfs(nodes[nid],f,d,t+1,visited)

for k in f:
    print k,f[k],d[k] class Node:
    def __init__(self,v):
        self.v = v
        self.c = [] Node def __init__(self,v):
        self.v = v
        self.c = [] __init__ self.v = v self.v self v v self.c = [] self.c self c [] self self v v def dfs(n,f,d,t,visited):
    visited.add(n.v)
    f[n.v] = t
    t2 = t
    for c in sorted(n.c,key=lambda x:x.v):
        if not c.v in visited:
            t2 = dfs(c,f,d,t2+1,visited)
    d[n.v] = t2+1
    return t2+1 dfs visited.add(n.v) visited.add visited add n.v n v f[n.v] = t f[n.v] f n.v n v t t2 = t t2 t for c in sorted(n.c,key=lambda x:x.v):
        if not c.v in visited:
            t2 = dfs(c,f,d,t2+1,visited)
     c sorted(n.c,key=lambda x:x.v) sorted n.c n c key=lambda x:x.v key lambda x:x.v x.v x v x if not c.v in visited:
            t2 = dfs(c,f,d,t2+1,visited)
     not c.v in visited c.v in visited c.v c v visited t2 = dfs(c,f,d,t2+1,visited) t2 dfs(c,f,d,t2+1,visited) dfs c f d t2+1 t2 1 visited d[n.v] = t2+1 d[n.v] d n.v n v t2+1 t2 1 return t2+1 t2+1 t2 1 n n f f d d t t visited visited n = int(raw_input()) n int(raw_input()) int raw_input() raw_input nodes = {} nodes {} for _ in range(n):
    entry = map(int,raw_input().split(' '))
    nid = entry[0]
    if not nid in nodes: nodes[nid] = Node(nid)
    k = entry[1]
    if k > 0:
        children = entry[2:]
        for c in children:
            if not c in nodes: nodes[c] = Node(c)
            nodes[nid].c.append(nodes[c]) _ range(n) range n entry = map(int,raw_input().split(' ')) entry map(int,raw_input().split(' ')) map int raw_input().split(' ') ().split () raw_input split ' ' nid = entry[0] nid entry[0] entry 0 if not nid in nodes: nodes[nid] = Node(nid)
     not nid in nodes nid in nodes nid nodes k = entry[1] k entry[1] entry 1 if k > 0:
        children = entry[2:]
        for c in children:
            if not c in nodes: nodes[c] = Node(c)
            nodes[nid].c.append(nodes[c]) k > 0 k 0 children = entry[2:] children entry[2:] entry 2: 2 for c in children:
            if not c in nodes: nodes[c] = Node(c)
            nodes[nid].c.append(nodes[c]) c children if not c in nodes: nodes[c] = Node(c)
             not c in nodes c in nodes c nodes nodes[nid].c.append(nodes[c]) [nid].c.append [nid].c [nid] nodes nid c append nodes[c] nodes c f = {} f {} d = {} d {} visited = set() visited set() set t = dfs(nodes[1],f,d,1,visited) t dfs(nodes[1],f,d,1,visited) dfs nodes[1] nodes 1 f d 1 visited while len(visited) < len(nodes):
    for nid in nodes:
        if not nid in visited:
            t = dfs(nodes[nid],f,d,t+1,visited) len(visited) < len(nodes) len(visited) len visited len(nodes) len nodes for nid in nodes:
        if not nid in visited:
            t = dfs(nodes[nid],f,d,t+1,visited) nid nodes if not nid in visited:
            t = dfs(nodes[nid],f,d,t+1,visited) not nid in visited nid in visited nid visited t = dfs(nodes[nid],f,d,t+1,visited) t dfs(nodes[nid],f,d,t+1,visited) dfs nodes[nid] nodes nid f d t+1 t 1 visited for k in f:
    print k,f[k],d[k] k f print k f[k] f k d[k] d k d = {} {} d t = dfs(nodes[nid],f,d,t+1,visited) dfs(nodes[nid],f,d,t+1,visited) t k = entry[1] entry[1] k nid = entry[0] entry[0] nid def dfs(n,f,d,t,visited):
    visited.add(n.v)
    f[n.v] = t
    t2 = t
    for c in sorted(n.c,key=lambda x:x.v):
        if not c.v in visited:
            t2 = dfs(c,f,d,t2+1,visited)
    d[n.v] = t2+1
    return t2+1 def dfs(n,f,d,t,visited):
    visited.add(n.v)
    f[n.v] = t
    t2 = t
    for c in sorted(n.c,key=lambda x:x.v):
        if not c.v in visited:
            t2 = dfs(c,f,d,t2+1,visited)
    d[n.v] = t2+1
    return t2+1 dfs children = entry[2:] entry[2:] children f = {} {} f n = int(raw_input()) int(raw_input()) n entry = map(int,raw_input().split(' ')) map(int,raw_input().split(' ')) entry t = dfs(nodes[1],f,d,1,visited) dfs(nodes[1],f,d,1,visited) t class Node:
    def __init__(self,v):
        self.v = v
        self.c = [] class Node:
    def __init__(self,v):
        self.v = v
        self.c = [] Node visited = set() set() visited nodes = {} {} nodes
class Node:
    def __init__(self,v):
        self.v = v
        self.c = []

def dfs(n,f,d,t,visited):
    visited.add(n.v)
    f[n.v] = t
    t2 = t
    for c in sorted(n.c,key=lambda x:x.v):
        if not c.v in visited:
            t2 = dfs(c,f,d,t2+1,visited)
    d[n.v] = t2+1
    return t2+1

n = int(raw_input())
nodes = {}
for _ in range(n):
    entry = map(int,raw_input().split(' '))
    nid = entry[0]
    if not nid in nodes: nodes[nid] = Node(nid)
    k = entry[1]
    if k > 0:
        children = entry[2:]
        for c in children:
            if not c in nodes: nodes[c] = Node(c)
            nodes[nid].c.append(nodes[c])

f = {}
d = {}
visited = set()
t = dfs(nodes[1],f,d,1,visited)
while len(visited) < len(nodes):
    for nid in nodes:
        if not nid in visited:
            t = dfs(nodes[nid],f,d,t+1,visited)

for k in f:
    print k,f[k],d[k]