1278_E. Tests for problem D_32165
We had a really tough time generating tests for problem D. In order to prepare strong tests, we had to solve the following problem.

Given an undirected labeled tree consisting of n vertices, find a set of segments such that:

  1. both endpoints of each segment are integers from 1 to 2n, and each integer from 1 to 2n should appear as an endpoint of exactly one segment; 
  2. all segments are non-degenerate; 
  3. for each pair (i, j) such that i ≠ j, i ∈ [1, n] and j ∈ [1, n], the vertices i and j are connected with an edge if and only if the segments i and j intersect, but neither segment i is fully contained in segment j, nor segment j is fully contained in segment i. 



Can you solve this problem too?

Input

The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of vertices in the tree.

Then n - 1 lines follow, each containing two integers x_i and y_i (1 ≤ x_i, y_i ≤ n, x_i ≠ y_i) denoting the endpoints of the i-th edge.

It is guaranteed that the given graph is a tree.

Output

Print n pairs of integers, the i-th pair should contain two integers l_i and r_i (1 ≤ l_i < r_i ≤ 2n) — the endpoints of the i-th segment. All 2n integers you print should be unique.

It is guaranteed that the answer always exists.

Examples

Input


6
1 2
1 3
3 4
3 5
2 6


Output


9 12
7 10
3 11
1 5
2 4
6 8


Input


1


Output


1 2
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Rustam Musin (t.me/musin_acm)
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    ETestiDlyaZadachiD solver = new ETestiDlyaZadachiD();
    solver.solve(1, in, out);
    out.close();
  }

  static class ETestiDlyaZadachiD {
    int n;
    List<Integer>[] g;

    public void solve(int testNumber, InputReader in, OutputWriter out) {
      n = in.readInt();
      g = new List[n];
      for (int i = 0; i < n; i++) {
        g[i] = new ArrayList<>();
      }
      for (int i = 0; i < n - 1; i++) {
        int x = in.readInt() - 1;
        int y = in.readInt() - 1;
        g[x].add(y);
        g[y].add(x);
      }
      if (false) {
        n = (int) 1e5;
        g = new List[n];
        for (int i = 0; i < n; i++) {
          g[i] = new ArrayList<>();
          if (i + 1 < n) g[i].add(i + 1);
        }
      }
//    Node answer = dfs(0, -1);
      ETestiDlyaZadachiD.Node answer = bfs();
      int offset = answer.start;
      ETestiDlyaZadachiD.Segment[] toPrint = new ETestiDlyaZadachiD.Segment[n];
      for (int i = 0; i < n; i++) {
        ETestiDlyaZadachiD.Segment cur = answer.segments.get(i);
        toPrint[cur.index] = cur;
      }
      for (int i = 0; i < n; i++) out.printLine(toPrint[i].from - offset + 1, toPrint[i].to - offset + 1);
    }

    ETestiDlyaZadachiD.Node bfs() {
      int[] parent = new int[n];
      Arrays.fill(parent, -1);
      int[] q = new int[n];
      int qs = 0;
      q[qs++] = 0;
      boolean[] used = new boolean[n];
      used[0] = true;
      for (int qi = 0; qi < qs; qi++) {
        int v = q[qi];
        for (int to : g[v])
          if (!used[to]) {
            parent[to] = v;
            q[qs++] = to;
            used[to] = true;
          }
      }
      ETestiDlyaZadachiD.Node[] res = new ETestiDlyaZadachiD.Node[n];
      for (int it = n - 1; it >= 0; it--) {
        int v = q[it];
        List<ETestiDlyaZadachiD.Node> children = new ArrayList<>();
        for (int to : g[v]) if (to != parent[v]) children.add(res[to]);
        if (children.isEmpty()) {
          List<ETestiDlyaZadachiD.Segment> cur = new ArrayList<>();
          cur.add(new ETestiDlyaZadachiD.Segment(v, 0, 1));
          res[v] = new ETestiDlyaZadachiD.Node(0, cur);
          continue;
        }

        int maxSize = 0;
        for (var c : children) maxSize = Math.max(maxSize, c.size());
        for (int i = 0; i < children.size(); i++) {
          if (children.get(i).size() == maxSize) {
            Collections.swap(children, 0, i);
            break;
          }
        }
        ETestiDlyaZadachiD.Node firstGroup = children.get(0);
        ETestiDlyaZadachiD.Segment firstPartParent = firstGroup.getLast();
        ETestiDlyaZadachiD.Segment curSegment = new ETestiDlyaZadachiD.Segment(v, firstPartParent.to++, -1);
        int nextEnd = curSegment.from + 2;
        for (int i = 1; i < children.size(); i++)
          firstGroup.add(children.get(i), nextEnd++);
        curSegment.to = nextEnd;
        firstGroup.segments.add(curSegment);
        res[v] = firstGroup;
      }
      return res[0];
    }

    static class Node {
      int start;
      List<ETestiDlyaZadachiD.Segment> segments;

      Node(int start, List<ETestiDlyaZadachiD.Segment> segments) {
        this.start = start;
        this.segments = segments;
      }

      int size() {
        return segments.size();
      }

      void add(ETestiDlyaZadachiD.Node other, int putLastAt) {
        int addOffset = -2 * other.size() + 1 + start - other.start;
        List<ETestiDlyaZadachiD.Segment> oSeg = other.segments;
        for (int i = 0; i < oSeg.size(); i++) {
          ETestiDlyaZadachiD.Segment cur = oSeg.get(i);
          cur.from += addOffset;
          cur.to += addOffset;
          segments.add(cur);
          if (i + 1 == oSeg.size()) cur.to = putLastAt;
        }
        start -= oSeg.size() * 2 - 1;
      }

      ETestiDlyaZadachiD.Segment getLast() {
        return segments.get(segments.size() - 1);
      }

    }

    static class Segment {
      int index;
      int from;
      int to;

      public Segment(int index, int from, int to) {
        this.index = index;
        this.from = from;
        this.to = to;
      }

      public String toString() {
        return "Segment{" +
            "index=" + index +
            ", from=" + from +
            ", to=" + to +
            '}';
      }

    }

  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void printLine(Object... objects) {
      print(objects);
      writer.println();
    }

    public void close() {
      writer.close();
    }

  }

  static class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public int readInt() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);

    }

  }
}

