n = int(input())
g = [[] for i in range(n)]
for i in range(n):
    g[i] = list(map(lambda x:int(x)-1,input().split()))[2:]

def dfs(v,t):
    t += 1
    d[v] = t
    for i in g[v]:
        if d[i]==-1:
            t = dfs(i,t)
    t += 1
    f[v] = t
    return t

t = 0
d = [-1]*n
f = [-1]*n

for i in range(n):
    if d[i]==-1:
        t = dfs(i,t)

for i in range(n):
    print(i+1,d[i],f[i]) 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)] for i in range(n):
    g[i] = list(map(lambda x:int(x)-1,input().split()))[2:] i range(n) range n g[i] = list(map(lambda x:int(x)-1,input().split()))[2:] g[i] g i list(map(lambda x:int(x)-1,input().split()))[2:] (map(lambda x:int(x)-1,input().split())) list map(lambda x:int(x)-1,input().split()) map lambda x:int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split 2: 2 def dfs(v,t):
    t += 1
    d[v] = t
    for i in g[v]:
        if d[i]==-1:
            t = dfs(i,t)
    t += 1
    f[v] = t
    return t dfs t += 1 t 1 d[v] = t d[v] d v t for i in g[v]:
        if d[i]==-1:
            t = dfs(i,t)
     i g[v] g v if d[i]==-1:
            t = dfs(i,t)
     d[i]==-1 d[i] d i -1 t = dfs(i,t) t dfs(i,t) dfs i t t += 1 t 1 f[v] = t f[v] f v t return t t v v t t t = 0 t 0 d = [-1]*n d [-1]*n [-1] -1 n f = [-1]*n f [-1]*n [-1] -1 n for i in range(n):
    if d[i]==-1:
        t = dfs(i,t) i range(n) range n if d[i]==-1:
        t = dfs(i,t) d[i]==-1 d[i] d i -1 t = dfs(i,t) t dfs(i,t) dfs i t 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 g = [[] for i in range(n)] [[] for i in range(n)] g def dfs(v,t):
    t += 1
    d[v] = t
    for i in g[v]:
        if d[i]==-1:
            t = dfs(i,t)
    t += 1
    f[v] = t
    return t def dfs(v,t):
    t += 1
    d[v] = t
    for i in g[v]:
        if d[i]==-1:
            t = dfs(i,t)
    t += 1
    f[v] = t
    return t dfs d = [-1]*n [-1]*n d t = 0 0 t t = dfs(i,t) dfs(i,t) t f = [-1]*n [-1]*n f n = int(input()) int(input()) n
n = int(input())
g = [[] for i in range(n)]
for i in range(n):
    g[i] = list(map(lambda x:int(x)-1,input().split()))[2:]

def dfs(v,t):
    t += 1
    d[v] = t
    for i in g[v]:
        if d[i]==-1:
            t = dfs(i,t)
    t += 1
    f[v] = t
    return t

t = 0
d = [-1]*n
f = [-1]*n

for i in range(n):
    if d[i]==-1:
        t = dfs(i,t)

for i in range(n):
    print(i+1,d[i],f[i])
