n = int(input())
M = [[0]*n for _ in range(n)]

for _ in range(n):
    u, k, *V = map(int, input().split())
    if k == 0:
        continue
    else:
        for v in V:
            M[u-1][v-1] = 1

color = ['White']*n

time = 0
d = [0]*n
f = [0]*n
def dfs_visit(u=0):
    global time
    color[u] = 'Gray'
    time += 1
    d[u] = time
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == 'White':
            dfs_visit(v)
    color[u] = "Black"
    time += 1
    f[u] = time

def dfs():
    for u in range(n):
        if color[u] == 'White':
            dfs_visit(u)
    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u]))


dfs() n = int(input()) n int(input()) int input() input [0]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0]*n [0] 0 n M = [[0]*n for _ in range(n)] M [[0]*n for _ in range(n)] for _ in range(n):
    u, k, *V = map(int, input().split())
    if k == 0:
        continue
    else:
        for v in V:
            M[u-1][v-1] = 1 _ range(n) range n u, k, *V = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split k *V V if k == 0:
        continue
    else:
        for v in V:
            M[u-1][v-1] = 1 k == 0 k 0 continue for v in V:
            M[u-1][v-1] = 1 v V M[u-1][v-1] = 1 M[u-1][v-1] [u-1] M u-1 u 1 v-1 v 1 1 color = ['White']*n color ['White']*n ['White'] 'White' n time = 0 time 0 d = [0]*n d [0]*n [0] 0 n f = [0]*n f [0]*n [0] 0 n def dfs_visit(u=0):
    global time
    color[u] = 'Gray'
    time += 1
    d[u] = time
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == 'White':
            dfs_visit(v)
    color[u] = "Black"
    time += 1
    f[u] = time dfs_visit global time color[u] = 'Gray' color[u] color u 'Gray' time += 1 time 1 d[u] = time d[u] d u time for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == 'White':
            dfs_visit(v)
     v range(n) range n if M[u][v] == 0:
            continue
         M[u][v] == 0 M[u][v] [u] M u v 0 continue if color[v] == 'White':
            dfs_visit(v)
     color[v] == 'White' color[v] color v 'White' dfs_visit(v) dfs_visit v color[u] = "Black" color[u] color u "Black" time += 1 time 1 f[u] = time f[u] f u time u=0 u 0 def dfs():
    for u in range(n):
        if color[u] == 'White':
            dfs_visit(u)
    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u])) dfs for u in range(n):
        if color[u] == 'White':
            dfs_visit(u)
     u range(n) range n if color[u] == 'White':
            dfs_visit(u)
     color[u] == 'White' color[u] color u 'White' dfs_visit(u) dfs_visit u for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u])) u range(n) range n print('{} {} {}'.format(u+1, d[u], f[u])) print '{} {} {}'.format(u+1, d[u], f[u]) '{} {} {}'.format '{} {} {}' format u+1 u 1 d[u] d u f[u] f u dfs() dfs k, *V = map(int, input().split()) map(int, input().split()) k def dfs():
    for u in range(n):
        if color[u] == 'White':
            dfs_visit(u)
    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u])) def dfs():
    for u in range(n):
        if color[u] == 'White':
            dfs_visit(u)
    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u])) dfs n = int(input()) int(input()) n time = 0 0 time f = [0]*n [0]*n f color = ['White']*n ['White']*n color d = [0]*n [0]*n d u, k, *V = map(int, input().split()) map(int, input().split()) u M = [[0]*n for _ in range(n)] [[0]*n for _ in range(n)] M def dfs_visit(u=0):
    global time
    color[u] = 'Gray'
    time += 1
    d[u] = time
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == 'White':
            dfs_visit(v)
    color[u] = "Black"
    time += 1
    f[u] = time def dfs_visit(u=0):
    global time
    color[u] = 'Gray'
    time += 1
    d[u] = time
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == 'White':
            dfs_visit(v)
    color[u] = "Black"
    time += 1
    f[u] = time dfs_visit
n = int(input())
M = [[0]*n for _ in range(n)]

for _ in range(n):
    u, k, *V = map(int, input().split())
    if k == 0:
        continue
    else:
        for v in V:
            M[u-1][v-1] = 1

color = ['White']*n

time = 0
d = [0]*n
f = [0]*n
def dfs_visit(u=0):
    global time
    color[u] = 'Gray'
    time += 1
    d[u] = time
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == 'White':
            dfs_visit(v)
    color[u] = "Black"
    time += 1
    f[u] = time

def dfs():
    for u in range(n):
        if color[u] == 'White':
            dfs_visit(u)
    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u]))


dfs()
