def inpl():
    return list(map(int, input().split()))


def dfs(v, step):
    if f[v] != -1:
        return step
    f[v] = step
    step += 1
    for nv in E[v]:
        # print("now", v, nv, step)
        step = dfs(nv - 1, step)
    d[v] = step
    return step + 1


n = int(input())
E = [[] for i in range(n)]
for _ in range(n):
    tmp = inpl()
    u, k = tmp[:2]
    E[u - 1] = tmp[2:]

d = [-1 for i in range(n)]
f = [-1 for i in range(n)]

step = 1
for v in range(n):
    step = dfs(v, step)

for i in range(n):
    print(i + 1, f[i], d[i])
 def inpl():
    return list(map(int, input().split())) inpl return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def dfs(v, step):
    if f[v] != -1:
        return step
    f[v] = step
    step += 1
    for nv in E[v]:
        # print("now", v, nv, step)
        step = dfs(nv - 1, step)
    d[v] = step
    return step + 1 dfs if f[v] != -1:
        return step
     f[v] != -1 f[v] f v -1 return step step f[v] = step f[v] f v step step += 1 step 1 for nv in E[v]:
        # print("now", v, nv, step)
        step = dfs(nv - 1, step)
     nv E[v] E v step = dfs(nv - 1, step) step dfs(nv - 1, step) dfs nv - 1 nv 1 step d[v] = step d[v] d v step return step + 1 step + 1 step 1 v v step step 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) [] E = [[] for i in range(n)] E [[] for i in range(n)] for _ in range(n):
    tmp = inpl()
    u, k = tmp[:2]
    E[u - 1] = tmp[2:] _ range(n) range n tmp = inpl() tmp inpl() inpl u, k = tmp[:2] u tmp[:2] tmp :2 2 k E[u - 1] = tmp[2:] E[u - 1] E u - 1 u 1 tmp[2:] tmp 2: 2 -1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) -1 d = [-1 for i in range(n)] d [-1 for i in range(n)] -1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) -1 f = [-1 for i in range(n)] f [-1 for i in range(n)] step = 1 step 1 for v in range(n):
    step = dfs(v, step) v range(n) range n step = dfs(v, step) step dfs(v, step) dfs v step for i in range(n):
    print(i + 1, f[i], d[i]) i range(n) range n print(i + 1, f[i], d[i]) print i + 1 i 1 f[i] f i d[i] d i k = tmp[:2] tmp[:2] k d = [-1 for i in range(n)] [-1 for i in range(n)] d tmp = inpl() inpl() tmp def dfs(v, step):
    if f[v] != -1:
        return step
    f[v] = step
    step += 1
    for nv in E[v]:
        # print("now", v, nv, step)
        step = dfs(nv - 1, step)
    d[v] = step
    return step + 1 def dfs(v, step):
    if f[v] != -1:
        return step
    f[v] = step
    step += 1
    for nv in E[v]:
        # print("now", v, nv, step)
        step = dfs(nv - 1, step)
    d[v] = step
    return step + 1 dfs E = [[] for i in range(n)] [[] for i in range(n)] E u, k = tmp[:2] tmp[:2] u f = [-1 for i in range(n)] [-1 for i in range(n)] f step = dfs(v, step) dfs(v, step) step def inpl():
    return list(map(int, input().split())) def inpl():
    return list(map(int, input().split())) inpl n = int(input()) int(input()) n step = 1 1 step
def inpl():
    return list(map(int, input().split()))


def dfs(v, step):
    if f[v] != -1:
        return step
    f[v] = step
    step += 1
    for nv in E[v]:
        # print("now", v, nv, step)
        step = dfs(nv - 1, step)
    d[v] = step
    return step + 1


n = int(input())
E = [[] for i in range(n)]
for _ in range(n):
    tmp = inpl()
    u, k = tmp[:2]
    E[u - 1] = tmp[2:]

d = [-1 for i in range(n)]
f = [-1 for i in range(n)]

step = 1
for v in range(n):
    step = dfs(v, step)

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

