n = int(input())
a = [[] for i in range(n)]

for i in range(n):
    v = list(map(int, input().split()))
    u = v[0] - 1
    for j in v[2:]:
        a[u].append(j-1)

d = [0] * n
f = [0] * n
isDiscovered = [False] * n
time_stamp = 0

def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp += 1
    d[x] = time_stamp
    for i in a[x]:
        if not isDiscovered[i]:
            dfs(i)
    time_stamp += 1
    f[x] = time_stamp

for i in range(n):
    if not isDiscovered[i]:
        dfs(i)

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) [] a = [[] for i in range(n)] a [[] for i in range(n)] for i in range(n):
    v = list(map(int, input().split()))
    u = v[0] - 1
    for j in v[2:]:
        a[u].append(j-1) i range(n) range n v = list(map(int, input().split())) v list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u = v[0] - 1 u v[0] - 1 v[0] v 0 1 for j in v[2:]:
        a[u].append(j-1) j v[2:] v 2: 2 a[u].append(j-1) [u].append [u] a u append j-1 j 1 d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n isDiscovered = [False] * n isDiscovered [False] * n [False] False n time_stamp = 0 time_stamp 0 def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp += 1
    d[x] = time_stamp
    for i in a[x]:
        if not isDiscovered[i]:
            dfs(i)
    time_stamp += 1
    f[x] = time_stamp dfs global time_stamp isDiscovered [x] = True isDiscovered [x] isDiscovered x True time_stamp += 1 time_stamp 1 d[x] = time_stamp d[x] d x time_stamp for i in a[x]:
        if not isDiscovered[i]:
            dfs(i)
     i a[x] a x if not isDiscovered[i]:
            dfs(i)
     not isDiscovered[i] isDiscovered[i] isDiscovered i dfs(i) dfs i time_stamp += 1 time_stamp 1 f[x] = time_stamp f[x] f x time_stamp x x for i in range(n):
    if not isDiscovered[i]:
        dfs(i) i range(n) range n if not isDiscovered[i]:
        dfs(i) not isDiscovered[i] isDiscovered[i] isDiscovered i dfs(i) dfs i 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 a = [[] for i in range(n)] [[] for i in range(n)] a u = v[0] - 1 v[0] - 1 u d = [0] * n [0] * n d time_stamp = 0 0 time_stamp n = int(input()) int(input()) n def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp += 1
    d[x] = time_stamp
    for i in a[x]:
        if not isDiscovered[i]:
            dfs(i)
    time_stamp += 1
    f[x] = time_stamp def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp += 1
    d[x] = time_stamp
    for i in a[x]:
        if not isDiscovered[i]:
            dfs(i)
    time_stamp += 1
    f[x] = time_stamp dfs f = [0] * n [0] * n f v = list(map(int, input().split())) list(map(int, input().split())) v isDiscovered = [False] * n [False] * n isDiscovered
n = int(input())
a = [[] for i in range(n)]

for i in range(n):
    v = list(map(int, input().split()))
    u = v[0] - 1
    for j in v[2:]:
        a[u].append(j-1)

d = [0] * n
f = [0] * n
isDiscovered = [False] * n
time_stamp = 0

def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp += 1
    d[x] = time_stamp
    for i in a[x]:
        if not isDiscovered[i]:
            dfs(i)
    time_stamp += 1
    f[x] = time_stamp

for i in range(n):
    if not isDiscovered[i]:
        dfs(i)

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