Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	g := graph{}
	g.ee = make([]Edges, n)
	g.visited = make([]bool, n)
	g.found = make([]int, n)
	g.leave = make([]int, n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner) - 1
		k := getNextInt(scanner)
		for j := 0; j < k; j++ {
			v := getNextInt(scanner) - 1
			g.ee[u] = append(g.ee[u], Edge{
				to: v,
				id: u,
			})
		}
	}
	for i := 0; i < n; i++ {
		sort.Sort(g.ee[i])
	}
	for i := 0; i < n; i++ {
		if g.visited[i] {
			continue
		}
		g.dfs(i)
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", i+1, g.found[i], g.leave[i]))
	}
}

// Edge ...
type Edge struct {
	to, id int
}

type Edges []Edge

func (a Edges) Len() int           { return len(a) }
func (a Edges) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Edges) Less(i, j int) bool { return a[i].id < a[j].id }

type graph struct {
	ee           []Edges
	t            int
	n            int
	visited      []bool
	found, leave []int
}

func (g *graph) dfs(i int) {
	g.visited[i] = true
	g.t++
	g.found[i] = g.t
	for _, e := range g.ee[i] {
		if g.visited[e.to] {
			continue
		}
		g.dfs(e.to)
	}
	g.t++
	g.leave[i] = g.t
}

C++: #line 1 "main.cpp"
#include <cstdio>
#include <algorithm>
#include <vector>

#line 1 "~/git/library/utility/io.cpp"



/**
 * @brief 入出力
 * @author えびちゃん
 */

#include <cstddef>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <tuple>
#include <utility>

class format {
public:
  using size_type = size_t;

private:
  char const* M_fmt;
  size_type M_nvars = 0;
  size_type M_error = -1;

  void M_print(std::ostream& os, char const* pos) const {
    while (*pos) {
      if (*pos == '{' || *pos == '}') ++pos;
      os << *pos++;
    }
  }

  template <typename Tp, typename... Args>
  void M_print(std::ostream& os, char const* pos, Tp const& x, Args const&... xs) const {
    while (true) {
      if (*pos == '{') {
        if (pos[1] == '{') {
          ++pos;
          os << '{';
        } else {
          char const* next = M_print_formatted(os, pos, x);
          return M_print(os, next, xs...);
        }
      } else {
        if (*pos == '}') ++pos;
        os << *pos;
      }
      ++pos;
    }
    char const* next = M_print_formatted(os, pos, x);
    M_print(os, next, xs...);
  }

  template <typename Tp>
  char const* M_print_formatted(std::ostream& os, char const* pos, Tp const& x) const {
    // parse flags, preferably
    while (*++pos != '}') {}
    os << x;
    return ++pos;
  }

  void M_scan(std::istream& is, char const* pos) const {
    while (true) {
      if (*pos == '{' || *pos == '}') ++pos;
      if (isspace(*pos)) {
        while (isspace(is.peek())) is.get();
      } else {
        if (is.peek() == *pos) {
          ++pos;
          is.get();
        } else {
          return;
        }
      }
    }
  }

  template <typename Tp, typename... Args>
  void M_scan(std::istream& is, char const* pos, Tp& x, Args&&... xs) const {
    while (true) {
      if (*pos == '{') {
        if (pos[1] == '{') {
          if (is.peek() == '{') {
            ++pos;
            is.get();
          } else {
            return;
          }
        } else {
          char const* next = M_scan_formatted(is, pos, x);
          return M_scan(is, next, xs...);
        }
      } else if (isspace(*pos)) {
        while (isspace(is.peek())) is.get();
        ++pos;
      } else {
        if (*pos == '}') ++pos;
        if (is.peek() == *pos) {
          ++pos;
          is.get();
        } else {
          return;
        }
      }
    }
  }

  template <typename Tp>
  char const* M_scan_formatted(std::istream& is, char const* pos, Tp& x) const {
    // parse flags, preferably
    while (*++pos != '}') {}
    is >> x;
    return ++pos;
  }

public:
  constexpr format(char const* fmt): M_fmt(fmt) {
    bool opens = 0;
    size_type i = 0;
    for (; fmt[i]; ++i) {
      if (fmt[i] == '{') {
        if (fmt[i+1] == '{') { ++i; continue; }  // escaped
        if (opens) { M_error = i; return; }
        opens = true;
      } else if (fmt[i] == '}') {
        if (fmt[i+1] == '}') { ++i; continue; }  // escaped
        if (!opens) { M_error = i; return; }
        opens = false;
        ++M_nvars;
      }
    }
    if (opens) { M_error = i; return; }
  }

  template <typename... Args>
  void print_(std::ostream& os, Args const&... xs) const {
    M_print(os, M_fmt, xs...);
  }

  template <typename... Args>
  void scan_(std::istream& is, Args&&... xs) const {
    M_scan(is, M_fmt, xs...);
  }

  constexpr size_type count() const { return M_nvars; }
  constexpr size_type error() const { return M_error; }
};

#define VA_COUNT(...)                                           \
  std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value

#define fprint(os, fmt, ...) (void)({                           \
      constexpr format fmt_(fmt);                               \
      constexpr size_t lhs = fmt_.count();                      \
      constexpr size_t rhs = VA_COUNT(__VA_ARGS__);             \
      static_assert(lhs == rhs, "size mismatch");               \
      static_assert(fmt_.error()+1 == 0, "misformatted");       \
      fmt_.print_(os, ##__VA_ARGS__);                           \
    })

#define fprintln(os, fmt, ...) (void)({         \
      fprint(os, fmt, ##__VA_ARGS__);           \
      os << '\n';;                              \
    })

#define print(...) fprint(std::cout, ##__VA_ARGS__)
#define println(...) fprintln(std::cout, ##__VA_ARGS__)
#define eprint(...) fprint(std::cerr, ##__VA_ARGS__)
#define eprintln(...) fprintln(std::cerr, ##__VA_ARGS__)

#define fscan(is, fmt, ...) (void)({                            \
      constexpr format fmt_(fmt);                               \
      constexpr size_t lhs = fmt_.count();                      \
      constexpr size_t rhs = VA_COUNT(__VA_ARGS__);             \
      static_assert(lhs == rhs, "size mismatch");               \
      static_assert(fmt_.error()+1 == 0, "misformatted");       \
      fmt_.scan_(is, ##__VA_ARGS__);                            \
    })

#define scan(...) fscan(std::cin, __VA_ARGS__)

__attribute__((constructor))
void ioinit() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cerr.tie(nullptr);
  std::cout << std::fixed << std::setprecision(16);
}


#line 1 "~/git/library/utility/literals.cpp"



/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#line 10 "~/git/library/utility/literals.cpp"
#include <cstdint>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

constexpr int32_t  operator ""_i32(unsigned long long n) { return n; }
constexpr int64_t  operator ""_i64(unsigned long long n) { return n; }
constexpr uint32_t operator ""_u32(unsigned long long n) { return n; }
constexpr uint64_t operator ""_u64(unsigned long long n) { return n; }


#line 1 "~/git/library/utility/make/pre17/vector.cpp"
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */

#ifndef H_make_vector
#define H_make_vector

#line 10 "~/git/library/utility/make/pre17/vector.cpp"
#include <type_traits>
#line 12 "~/git/library/utility/make/pre17/vector.cpp"

namespace detail {
  template <typename Tp, size_t N>
  std::vector<Tp> make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N == 1), Tp const&>::type x
  ) {
    return std::vector<Tp>(sizes[0], x);
  }
  template <typename Tp, size_t N>
  auto make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N > 1), Tp const&>::type x
  ) {
    size_t size = sizes[N-1];
    sizes.pop_back();
    return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
        size, make_vector<Tp, N-1>(sizes, x)
    );
  }
}  // detail::

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x = Tp()) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

#endif  /* !defined(H_make_vector) */
#line 1 "~/git/library/utility/make/fix_point.cpp"
/**
 * @brief ラムダ式の再帰
 * @author えびちゃん
 */

#ifndef H_make_fix_point
#define H_make_fix_point

#line 10 "~/git/library/utility/make/fix_point.cpp"

template <typename Fn>
class fix_point: Fn {
public:
  explicit constexpr fix_point(Fn&& f) noexcept: Fn(std::forward<Fn>(f)) {}

  template <typename... Args>
  constexpr decltype(auto) operator ()(Args&&... args) const {
    return Fn::operator ()(*this, std::forward<Args>(args)...);
  }
};

template <typename Fn>
static inline constexpr decltype(auto) make_fix_point(Fn&& f) noexcept {
  return fix_point<Fn>{std::forward<Fn>(f)};
}

#endif  /* !defined(H_make_fix_point) */
#line 9 "main.cpp"

int main() {
  size_t n;
  scan("{}", n);

  std::vector<std::vector<size_t>> g(n+1);
  for (size_t i = 0; i < n; ++i) {
    g[0].push_back(i);
    size_t u, k;
    scan("{} {}", u, k);
    for (size_t j = 0; j < k; ++j) {
      size_t v;
      scan("{}", v);
      g[u].push_back(v);
    }
  }

  auto res = make_vector({2_zu, n+1}, -1_zu);
  size_t t = 0;
  make_fix_point([&](auto&& dfs, size_t v) -> void {
    res[0][v] = t++;
    for (auto u: g[v]) {
      if (res[0][u] == -1_zu) dfs(u);
    }
    res[1][v] = t++;
  })(0);

  for (size_t i = 1; i <= n; ++i)
    println("{} {} {}", i, res[0][i], res[1][i]);
}