import sys

def dfs(i):
    global V, t, d, f

    if d[i] != 0:
        return

    d[i] = t
    t += 1
    for v in V[i]:
        dfs(v)

    f[i] = t
    t += 1

    return

lines = sys.stdin.readlines()
n = int(lines[0])
V = [[] for _ in range(n + 1)]

for i in range(1, n + 1):
    v = map(int, lines[i].split())
    V[v[0]] = v[2:]
d = [0] * (n + 1)
f = [0] * (n + 1)
t = 1

flag = True
while flag:
    flag = False
    for i in range(1, n + 1):
        if d[i] == 0:
            dfs(i)
            flag = True
            break

for i in range(1, n + 1):
    print i, d[i], f[i] import sys sys def dfs(i):
    global V, t, d, f

    if d[i] != 0:
        return

    d[i] = t
    t += 1
    for v in V[i]:
        dfs(v)

    f[i] = t
    t += 1

    return dfs global V, t, d, f if d[i] != 0:
        return

     d[i] != 0 d[i] d i 0 return d[i] = t d[i] d i t t += 1 t 1 for v in V[i]:
        dfs(v)

     v V[i] V i dfs(v) dfs v f[i] = t f[i] f i t t += 1 t 1 return i i lines = sys.stdin.readlines() lines sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines n = int(lines[0]) n int(lines[0]) int lines[0] lines 0 [] for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) [] V = [[] for _ in range(n + 1)] V [[] for _ in range(n + 1)] for i in range(1, n + 1):
    v = map(int, lines[i].split())
    V[v[0]] = v[2:] i range(1, n + 1) range 1 n + 1 n 1 v = map(int, lines[i].split()) v map(int, lines[i].split()) map int lines[i].split() [i].split [i] lines i split V[v[0]] = v[2:] V[v[0]] V v[0] v 0 v[2:] v 2: 2 d = [0] * (n + 1) d [0] * (n + 1) [0] 0 n + 1 n 1 f = [0] * (n + 1) f [0] * (n + 1) [0] 0 n + 1 n 1 t = 1 t 1 flag = True flag True while flag:
    flag = False
    for i in range(1, n + 1):
        if d[i] == 0:
            dfs(i)
            flag = True
            break flag flag = False flag False for i in range(1, n + 1):
        if d[i] == 0:
            dfs(i)
            flag = True
            break i range(1, n + 1) range 1 n + 1 n 1 if d[i] == 0:
            dfs(i)
            flag = True
            break d[i] == 0 d[i] d i 0 dfs(i) dfs i flag = True flag True break for i in range(1, n + 1):
    print i, d[i], f[i] i range(1, n + 1) range 1 n + 1 n 1 print i d[i] d i f[i] f i v = map(int, lines[i].split()) map(int, lines[i].split()) v t = 1 1 t flag = False False flag lines = sys.stdin.readlines() sys.stdin.readlines() lines def dfs(i):
    global V, t, d, f

    if d[i] != 0:
        return

    d[i] = t
    t += 1
    for v in V[i]:
        dfs(v)

    f[i] = t
    t += 1

    return def dfs(i):
    global V, t, d, f

    if d[i] != 0:
        return

    d[i] = t
    t += 1
    for v in V[i]:
        dfs(v)

    f[i] = t
    t += 1

    return dfs V = [[] for _ in range(n + 1)] [[] for _ in range(n + 1)] V f = [0] * (n + 1) [0] * (n + 1) f flag = True True flag n = int(lines[0]) int(lines[0]) n flag = True True flag d = [0] * (n + 1) [0] * (n + 1) d
import sys

def dfs(i):
    global V, t, d, f

    if d[i] != 0:
        return

    d[i] = t
    t += 1
    for v in V[i]:
        dfs(v)

    f[i] = t
    t += 1

    return

lines = sys.stdin.readlines()
n = int(lines[0])
V = [[] for _ in range(n + 1)]

for i in range(1, n + 1):
    v = map(int, lines[i].split())
    V[v[0]] = v[2:]
d = [0] * (n + 1)
f = [0] * (n + 1)
t = 1

flag = True
while flag:
    flag = False
    for i in range(1, n + 1):
        if d[i] == 0:
            dfs(i)
            flag = True
            break

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