In the Land of Fire there are n villages and n-1 bidirectional road, and there is a path between any pair of villages by roads. There are only two types of roads: stone ones and sand ones. Since the Land of Fire is constantly renovating, every morning workers choose a single road and flip its type (so it becomes a stone road if it was a sand road and vice versa). Also everyone here loves ramen, that's why every morning a ramen pavilion is set in the middle of every stone road, and at the end of each day all the pavilions are removed.

For each of the following m days, after another road is flipped, Naruto and Jiraiya choose a simple path — that is, a route which starts in a village and ends in a (possibly, the same) village, and doesn't contain any road twice. Since Naruto and Jiraiya also love ramen very much, they buy a single cup of ramen on each stone road and one of them eats it. Since they don't want to offend each other, they only choose routes where they can eat equal number of ramen cups. Since they both like traveling, they choose any longest possible path. After every renovation find the maximal possible length of a path (that is, the number of roads in it) they can follow.

Input

The first line contains the only positive integer n (2 ≤ n ≤ 500 000) standing for the number of villages in the Land of Fire.

Each of the following (n-1) lines contains a description of another road, represented as three positive integers u, v and t (1 ≤ u, v ≤ n, t ∈ \{0,1\}). The first two numbers denote the villages connected by the road, and the third denotes the initial type of the road: 0 for the sand one and 1 for the stone one. Roads are numbered from 1 to (n-1) in the order from the input.

The following line contains a positive integer m (1 ≤ m ≤ 500 000) standing for the number of days Naruto and Jiraiya travel for.

Each of the following m lines contains the single integer id (1 ≤ id ≤ n-1) standing for the index of the road whose type is flipped on the morning of corresponding day.

It is guaranteed that there is a road path between any pair of villages.

Output

Output m lines. In the i-th of them print the only integer denoting the maximal possible length of any valid path on the i-th day.

Example

Input


5
1 2 0
1 3 0
3 5 0
3 4 0
5
3
4
1
3
4


Output


3
2
3
3
2

Note

After the renovation of the 3-rd road the longest path consists of the roads 1, 2 and 4.

After the renovation of the 4-th road one of the longest paths consists of the roads 1 and 2.

After the renovation of the 1-st road one of the longest paths consists of the roads 1, 2 and 3.

After the renovation of the 3-rd road the longest path consists of the roads 1, 2 and 4.

After the renovation of the 4-rd road one of the longest paths consists of the roads 2 and 4.
10
5 7 0
2 10 1
1 5 0
6 8 0
4 9 1
2 5 1
10 8 0
2 3 1
4 2 1
10
9
9
9
5
2
5
7
2
3
2
 5
2 4 0
5 2 0
1 3 1
1 2 1
5
3
3
4
1
1
 20
9 11 0
1 5 0
1 14 0
5 17 0
14 3 0
16 6 0
9 2 0
6 4 0
11 10 0
12 7 0
8 18 0
13 1 0
18 11 0
8 6 0
5 10 0
5 15 0
2 20 0
19 17 0
7 17 0
20
9
11
11
14
14
5
5
10
10
4
4
18
17
18
17
17
8
8
15
17
 2
2 1 1
10
1
1
1
1
1
1
1
1
1
1

5
5
5
5
5
4
5
4
5
5
 2
3
2
3
2
 7
9
7
9
7
9
7
9
7
9
7
8
8
8
7
8
9
8
9
9
 1
0
1
0
1
0
1
0
1
0

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            DRoadsAndRamen solver = new DRoadsAndRamen();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class DRoadsAndRamen {
        int[][] edges;
        int alloc = 1;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            Node[] nodes = new Node[n];
            for (int i = 0; i < n; i++) {
                nodes[i] = new Node();
                nodes[i].id = i;
            }

            List<Query> allQuery = new ArrayList<>(1000000);
            edges = new int[n - 1][2];
            for (int i = 0; i < n - 1; i++) {
                int u = in.readInt() - 1;
                int v = in.readInt() - 1;
                edges[i][0] = u;
                edges[i][1] = v;
                Node a = nodes[u];
                Node b = nodes[v];
                a.adj.add(b);
                b.adj.add(a);
                if (in.readInt() == 1) {
                    allQuery.add(new Query(i));
                }
            }

            int m = in.readInt();
            Query[] qs = new Query[m];
            for (int i = 0; i < m; i++) {
                qs[i] = new Query(in.readInt() - 1);
                allQuery.add(qs[i]);
            }

            dfsForDepth(nodes[0], null);
            Node a = CompareUtils.maxOf(nodes, 0, n - 1, Node.sortByDepth);
            dfsForDepth(a, null);
            Node b = CompareUtils.maxOf(nodes, 0, n - 1, Node.sortByDepth);
            solve(a, nodes, allQuery);
            solve(b, nodes, allQuery);
            for (Query q : qs) {
                out.println(q.ans);
            }
        }

        public void solve(Node root, Node[] nodes, List<Query> qs) {
            dfsForLR(root, null);
            alloc = 1;
            int n = nodes.length;
            Node[] invIds = new Node[n + 1];
            for (Node node : nodes) {
                invIds[node.l] = node;
            }
            Segment seg = new Segment(1, n, i -> invIds[i].depth);
            for (Query q : qs) {
                Node u = nodes[edges[q.v][0]];
                Node v = nodes[edges[q.v][1]];
                if (u.depth < v.depth) {
                    Node tmp = u;
                    u = v;
                    v = tmp;
                }
                seg.update(u.l, u.r, 1, n);
                q.ans = Math.max(q.ans, seg.query(1, n, 1, n));
            }
        }

        public void dfsForLR(Node root, Node p) {
            root.l = alloc++;
            root.depth = p == null ? 0 : p.depth + 1;
            for (Node node : root.adj) {
                if (node == p) {
                    continue;
                }
                dfsForLR(node, root);
            }
            root.r = alloc - 1;
        }

        public void dfsForDepth(Node root, Node p) {
            root.depth = p == null ? 0 : p.depth + 1;
            for (Node node : root.adj) {
                if (node == p) {
                    continue;
                }
                dfsForDepth(node, root);
            }

        }

    }

    static class CompareUtils {
        private CompareUtils() {
        }

        public static <T> T maxOf(T[] a, int l, int r, Comparator<T> comp) {
            T x = a[l];
            for (int i = l; i <= r; i++) {
                x = max(x, a[i], comp);
            }
            return x;
        }

        public static <T> T max(T a, T b, Comparator<T> comp) {
            return comp.compare(a, b) >= 0 ? a : b;
        }

    }

    static class Node {
        int id;
        List<Node> adj = new ArrayList<>();
        int depth;
        int l;
        int r;
        static Comparator<Node> sortByDepth = (a, b) -> Integer.compare(a.depth, b.depth);

        public String toString() {
            return "" + (id + 1);
        }

    }

    static class Segment implements Cloneable {
        private Segment left;
        private Segment right;
        private int[] oe = new int[2];
        private boolean rev;

        private void modify() {
            rev = !rev;
            SequenceUtils.swap(oe, 0, 1);
        }

        public void pushUp() {
            for (int i = 0; i < 2; i++) {
                oe[i] = Math.max(left.oe[i], right.oe[i]);
            }
        }

        public void pushDown() {
            if (rev) {
                left.modify();
                right.modify();
                rev = false;
            }
        }

        public Segment(int l, int r, IntToIntegerFunction func) {
            if (l < r) {
                int m = DigitUtils.floorAverage(l, r);
                left = new Segment(l, m, func);
                right = new Segment(m + 1, r, func);
                pushUp();
            } else {
                oe[0] = func.apply(l);
                oe[1] = 0;
            }
        }

        private boolean covered(int ll, int rr, int l, int r) {
            return ll <= l && rr >= r;
        }

        private boolean noIntersection(int ll, int rr, int l, int r) {
            return ll > r || rr < l;
        }

        public void update(int ll, int rr, int l, int r) {
            if (noIntersection(ll, rr, l, r)) {
                return;
            }
            if (covered(ll, rr, l, r)) {
                modify();
                return;
            }
            pushDown();
            int m = DigitUtils.floorAverage(l, r);
            left.update(ll, rr, l, m);
            right.update(ll, rr, m + 1, r);
            pushUp();
        }

        public int query(int ll, int rr, int l, int r) {
            if (noIntersection(ll, rr, l, r)) {
                return 0;
            }
            if (covered(ll, rr, l, r)) {
                return oe[0];
            }
            pushDown();
            int m = DigitUtils.floorAverage(l, r);
            return Math.max(left.query(ll, rr, l, m),
                    right.query(ll, rr, m + 1, r));
        }

        private Segment deepClone() {
            Segment seg = clone();
            if (seg.left != null) {
                seg.left = seg.left.deepClone();
            }
            if (seg.right != null) {
                seg.right = seg.right.deepClone();
            }
            return seg;
        }

        protected Segment clone() {
            try {
                return (Segment) super.clone();
            } catch (CloneNotSupportedException e) {
                throw new RuntimeException(e);
            }
        }

        private void toString(StringBuilder builder) {
            if (left == null && right == null) {
                builder.append("val").append(",");
                return;
            }
            pushDown();
            left.toString(builder);
            right.toString(builder);
        }

        public String toString() {
            StringBuilder builder = new StringBuilder();
            deepClone().toString(builder);
            if (builder.length() > 0) {
                builder.setLength(builder.length() - 1);
            }
            return builder.toString();
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private static final int THRESHOLD = 1 << 13;
        private final Writer os;
        private StringBuilder cache = new StringBuilder(THRESHOLD * 2);

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        private void afterWrite() {
            if (cache.length() < THRESHOLD) {
                return;
            }
            flush();
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(String c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            return append(System.lineSeparator());
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static interface IntToIntegerFunction {
        int apply(int x);

    }

    static class Query {
        int v;
        int ans;

        public Query(int v) {
            this.v = v;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class SequenceUtils {
        public static void swap(int[] data, int i, int j) {
            int tmp = data[i];
            data[i] = data[j];
            data[j] = tmp;
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static int floorAverage(int x, int y) {
            return (x & y) + ((x ^ y) >> 1);
        }

    }
}

