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);
        }

    }
}


#include<bits/stdc++.h>
#define rint register int
#define ll long long
using namespace std;
struct node{int to,next,w;} e[1011000];
int tot,h[500100],n,rt1,rt2,dep[501000],U[501000],V[500100],W[500100];
inline void DFS(int now,int ffa){
	dep[now]=dep[ffa]+1;
	for(rint i=h[now];i;i=e[i].next){
		int to=e[i].to;if(to==ffa) continue;
		DFS(to,now);
	}
}
inline void add(int from,int to,int w){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;e[tot].w=w;}
struct Segment_Tree{
	int tag[2001000],Max[2001000][2];
	inline void Update(int now){
		Max[now][0]=max(Max[now<<1][0],Max[now<<1|1][0]);
		Max[now][1]=max(Max[now<<1][1],Max[now<<1|1][1]);
	}
	inline void	Pushdown(int now) {
		if(tag[now]){
			swap(Max[now<<1][0],Max[now<<1][1]);
			swap(Max[now<<1|1][0],Max[now<<1|1][1]);
			tag[now<<1]^=1;
			tag[now<<1|1]^=1;
			tag[now]=0;
		}
	}
	inline void Modify(int now,int l,int r,int x,int y) {
		if(x<=l&&r<=y) {swap(Max[now][0],Max[now][1]);tag[now]^=1;return ;}
		int mid=(l+r)>>1;Pushdown(now);
		if(x<=mid) Modify(now<<1,l,mid,x,y);
		if(y>mid)  Modify(now<<1|1,mid+1,r,x,y);
		Update(now);
	}
};
struct Tree{
	int rt,depp[500100],fa[501000],Seq[501000],cnt,in[500100],out[501000];
	Segment_Tree T;
	inline void Build(int now,int l,int r) {
		if(l==r) {T.Max[now][0]=depp[Seq[l]],T.Max[now][1]=T.tag[now]=0;return ;}
		int mid=(l+r)>>1;
		Build(now<<1,l,mid);
		Build(now<<1|1,mid+1,r);
		T.Update(now);
	}
	inline void Pre_DFS(int now,int ffa){
		fa[now]=ffa;
		Seq[++cnt]=now;
		in[now]=cnt;
		for(rint i=h[now];i;i=e[i].next){
			int to=e[i].to;
			if(to==ffa) continue;
			depp[to]=depp[now]+1;
			Pre_DFS(to,now);
		}
		out[now]=cnt;
	}
	inline void Buildd(){
		cnt=0;
		Pre_DFS(rt,0);
		Build(1,1,n);
		for(rint i=1;i<n;++i){
			if(depp[U[i]]>depp[V[i]]) swap(U[i],V[i]);
			if(W[i]) T.Modify(1,1,n,in[V[i]],out[V[i]]);
		}
	}
}T1,T2;
int main(){
	scanf("%d",&n);
	for(rint i=1;i<n;++i) {
		int u,v,w;scanf("%d%d%d",&u,&v,&w);
		add(u,v,w);add(v,u,w);
		U[i]=u;V[i]=v;W[i]=w;
	}
	DFS(1,0);
	int Max=0;
	for(rint i=1;i<=n;++i) if(dep[i]>Max) Max=dep[i],rt1=i;
	DFS(rt1,0);
	Max=0;
	for(rint i=1;i<=n;++i) if(dep[i]>Max) Max=dep[i],rt2=i;
	T1.rt=rt1,T2.rt=rt2;
//	cout<<rt1<<" "<<rt2<<"\n";
	T1.Buildd();
	T2.Buildd();
	int m;
	scanf("%d",&m);
	for(rint i=1;i<=m;++i){
		int idx;scanf("%d",&idx);
		if(T1.depp[U[idx]]>T1.depp[V[idx]]) swap(U[idx],V[idx]);
		T1.T.Modify(1,1,n,T1.in[V[idx]],T1.out[V[idx]]);
		if(T2.depp[U[idx]]>T2.depp[V[idx]]) swap(U[idx],V[idx]);
		T2.T.Modify(1,1,n,T2.in[V[idx]],T2.out[V[idx]]);
		cout<<max(T1.T.Max[1][0],T2.T.Max[1][0])<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#define rint register int
#define ll long long
using namespace std;
struct node{int to,next,w;} e[1011000];
int tot,h[500100],n,rt1,rt2,dep[501000],U[501000],V[500100],W[500100];
inline void DFS(int now,int ffa){
	dep[now]=dep[ffa]+1;
	for(rint i=h[now];i;i=e[i].next){
		int to=e[i].to;if(to==ffa) continue;
		DFS(to,now);
	}
}
inline void add(int from,int to,int w){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;e[tot].w=w;}
struct Segment_Tree{
	int tag[2001000],Max[2001000][2];
	inline void Update(int now){
		Max[now][0]=max(Max[now<<1][0],Max[now<<1|1][0]);
		Max[now][1]=max(Max[now<<1][1],Max[now<<1|1][1]);
	}
	inline void	Pushdown(int now) {
		if(tag[now]){
			swap(Max[now<<1][0],Max[now<<1][1]);
			swap(Max[now<<1|1][0],Max[now<<1|1][1]);
			tag[now<<1]^=1;
			tag[now<<1|1]^=1;
			tag[now]=0;
		}
	}
	inline void Modify(int now,int l,int r,int x,int y) {
		if(x<=l&&r<=y) {swap(Max[now][0],Max[now][1]);tag[now]^=1;return ;}
		int mid=(l+r)>>1;Pushdown(now);
		if(x<=mid) Modify(now<<1,l,mid,x,y);
		if(y>mid)  Modify(now<<1|1,mid+1,r,x,y);
		Update(now);
	}
};
struct Tree{
	int rt,depp[500100],fa[501000],Seq[501000],cnt,in[500100],out[501000];
	Segment_Tree T;
	inline void Build(int now,int l,int r) {
		if(l==r) {T.Max[now][0]=depp[Seq[l]],T.Max[now][1]=T.tag[now]=0;return ;}
		int mid=(l+r)>>1;
		Build(now<<1,l,mid);
		Build(now<<1|1,mid+1,r);
		T.Update(now);
	}
	inline void Pre_DFS(int now,int ffa){
		fa[now]=ffa;
		Seq[++cnt]=now;
		in[now]=cnt;
		for(rint i=h[now];i;i=e[i].next){
			int to=e[i].to;
			if(to==ffa) continue;
			depp[to]=depp[now]+1;
			Pre_DFS(to,now);
		}
		out[now]=cnt;
	}
	inline void Buildd(){
		Pre_DFS(rt,0);
		Build(1,1,n);
		for(rint i=1;i<n;++i){
			if(depp[U[i]]>depp[V[i]]) swap(U[i],V[i]);
			if(W[i]) T.Modify(1,1,n,in[V[i]],out[V[i]]);
		}
	}
}T1,T2;
int main(){
	scanf("%d",&n);
	for(rint i=1;i<n;++i) {
		int u,v,w;scanf("%d%d%d",&u,&v,&w);
		add(u,v,w);add(v,u,w);
		U[i]=u;V[i]=v;W[i]=w;
	}
	DFS(1,0);
	int Max=0;
	for(rint i=1;i<=n;++i) if(dep[i]>Max) Max=dep[i],rt1=i;
	DFS(rt1,0);
	Max=0;
	for(rint i=1;i<=n;++i) if(dep[i]>Max) Max=dep[i],rt2=i;
	T1.rt=rt1,T2.rt=rt2;
	T1.Buildd();
	T2.Buildd();
	int m;
	scanf("%d",&m);
	for(rint i=1;i<=m;++i){
		int idx;scanf("%d",&idx);
		if(T1.depp[U[i]]>T1.depp[V[i]]) swap(U[i],V[i]);
		T1.T.Modify(1,1,n,T1.in[V[idx]],T1.out[V[idx]]);
		if(T2.depp[U[i]]>T2.depp[V[i]]) swap(U[i],V[i]);
		T2.T.Modify(1,1,n,T2.in[V[idx]],T2.out[V[idx]]);
		cout<<max(T1.T.Max[1][0],T2.T.Max[1][0])<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#define rint register int
#define ll long long
using namespace std;
struct node{int to,next,w;} e[1011000];
int tot,h[500100],n,rt1,rt2,dep[501000],U[501000],V[500100],W[500100];
inline void DFS(int now,int ffa){
	dep[now]=dep[ffa]+1;
	for(rint i=h[now];i;i=e[i].next){
		int to=e[i].to;if(to==ffa) continue;
		DFS(to,now);
	}
}
inline void add(int from,int to,int w){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;e[tot].w=w;}
struct Segment_Tree{
	int tag[2001000],Max[2001000][2];
	inline void Update(int now){
		Max[now][0]=max(Max[now<<1][0],Max[now<<1|1][0]);
		Max[now][1]=max(Max[now<<1][1],Max[now<<1|1][1]);
	}
	inline void	Pushdown(int now) {
		if(tag[now]){
			swap(Max[now<<1][0],Max[now<<1][1]);
			swap(Max[now<<1|1][0],Max[now<<1|1][1]);
			tag[now<<1]^=1;
			tag[now<<1|1]^=1;
			tag[now]=0;
		}
	}
	inline void Modify(int now,int l,int r,int x,int y) {
		if(x<=l&&r<=y) {swap(Max[now][0],Max[now][1]);tag[now]^=1;return ;}
		int mid=(l+r)>>1;Pushdown(now);
		if(x<=mid) Modify(now<<1,l,mid,x,y);
		if(y>mid)  Modify(now<<1|1,mid+1,r,x,y);
		Update(now);
	}
};
struct Tree{
	int rt,depp[500100],fa[501000],Seq[501000],cnt,in[500100],out[501000];
	Segment_Tree T;
	inline void Build(int now,int l,int r) {
		if(l==r) {T.Max[now][0]=depp[Seq[l]],T.Max[now][1]=T.tag[now]=0;return ;}
		int mid=(l+r)>>1;
		Build(now<<1,l,mid);
		Build(now<<1|1,mid+1,r);
		T.Update(now);
	}
	inline void Pre_DFS(int now,int ffa){
		fa[now]=ffa;
		Seq[++cnt]=now;
		in[now]=cnt;
		for(rint i=h[now];i;i=e[i].next){
			int to=e[i].to;
			if(to==ffa) continue;
			depp[to]=depp[now]+1;
			Pre_DFS(to,now);
		}
		out[now]=cnt;
	}
	inline void Buildd(){
		Pre_DFS(rt,0);
		Build(1,1,n);
		for(rint i=1;i<n;++i){
			if(depp[U[i]]>depp[V[i]]) swap(U[i],V[i]);
			if(W[i]) T.Modify(1,1,n,in[V[i]],out[V[i]]);
		}
	}
}T1,T2;
int main(){
	scanf("%d",&n);
	for(rint i=1;i<n;++i) {
		int u,v,w;scanf("%d%d%d",&u,&v,&w);
		add(u,v,w);add(v,u,w);
		U[i]=u;V[i]=v;W[i]=w;
	}
	DFS(1,0);
	int Max=0;
	for(rint i=1;i<=n;++i) if(dep[i]>Max) Max=dep[i],rt1=i;
	DFS(rt1,0);
	Max=0;
	for(rint i=1;i<=n;++i) if(dep[i]>Max) Max=dep[i],rt2=i;
	T1.rt=rt1,T2.rt=rt2;
	cout<<rt1<<" "<<rt2<<"\n";
	T1.Buildd();
	T2.Buildd();
	int m;
	scanf("%d",&m);
	for(rint i=1;i<=m;++i){
		int idx;scanf("%d",&idx);
		if(T1.depp[U[i]]>T1.depp[V[i]]) swap(U[i],V[i]);
		T1.T.Modify(1,1,n,T1.in[V[idx]],T1.out[V[idx]]);
		if(T2.depp[U[i]]>T2.depp[V[i]]) swap(U[i],V[i]);
		T2.T.Modify(1,1,n,T2.in[V[idx]],T2.out[V[idx]]);
		cout<<max(T1.T.Max[1][0],T2.T.Max[1][0])<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 500500;

using namespace std;

int n;
int tim;
int A[N];
int B[N];
int c[N];
int l[N];
int d[N];
int id[N];
int tin[N];
int tout[N];
int f[N][20];
vector < int > v[N];

void dfs(int x, int p)
{
        tin[x] = ++tim;
        f[x][0] = p;
        for(int i = 1; i < 20; i++){
                f[x][i] = f[f[x][i - 1]][i - 1];
        }
        for(int i: v[x]){
                int y = A[i] ^ B[i] ^ x;
                if(y == p){
                        continue;
                }
                l[y] = l[x] + 1;
                d[y] = d[x] ^ c[i];
                dfs(y, x);
        }
        tout[x] = tim;

        id[tin[x]] = x;
}

bool isp(int x, int y)
{
        return tin[x] <= tin[y] && tout[x] >= tout[y];
}

int lca(int x, int y)
{
        if(isp(x, y)){
                return x;
        }
        if(isp(y, x)){
                return y;
        }
        for(int i = 19; i >= 0; i--){
                if(!isp(f[x][i], y)){
                        x = f[x][i];
                }
        }
        return f[x][0];
}

int len(int x, int y)
{
        return l[x] + l[y] - 2 * l[lca(x, y)];
}

vector < pair < int, int > >  get(int x)
{
        vector < pair < int, int > > res;
        for(int i = 1; i <= n; i++){
                res.push_back({len(x, i), i});
        }
        sort(res.begin(), res.end());
        reverse(res.begin(), res.end());
        return res;
}

int iv[N][3];
vector < pair < int, int > > g[3];
int fl[4 * N];
pair < int, int > f1[4 * N], f2[4 * N];

void app(int x)
{
        fl[x] ^= 1;
        swap(f1[x], f2[x]);
}

void push(int x)
{
        if(fl[x]){
                fl[x] = 0;
                app(x * 2);
                app(x * 2 + 1);
        }
}

int comb(int x)
{
        f1[x].fi = min(f1[x * 2].fi, f1[x * 2 + 1].fi);
        f1[x].se = min(f1[x * 2].se, f1[x * 2 + 1].se);
        f2[x].fi = min(f2[x * 2].fi, f2[x * 2 + 1].fi);
        f2[x].se = min(f2[x * 2].se, f2[x * 2 + 1].se);
}

void build(int x, int l, int r)
{
        f1[x] = f2[x] = {n, n};
        if(l == r){
                int a = id[l];
                if(d[a]){
                        f1[x] = {iv[a][1], iv[a][2]};
                } else{
                        f2[x] = {iv[a][1], iv[a][2]};
                }
                return;
        }
        int m = (l + r) / 2;
        build(x * 2, l, m);
        build(x * 2 + 1, m + 1, r);
        comb(x);
}

void upd(int x, int l, int r, int tl, int tr)
{
        if(tl > tr){
                return;
        } else if(l == tl && r == tr){
                app(x);
                return;
        }
        push(x);
        int m = (l + r) / 2;
        upd(x  * 2, l, m, tl, min(m, tr));
        upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr);
        comb(x);
}

int get(int x, int l, int r, int y)
{
        if(l == r){
                return d[id[l]] ^ fl[x];
        }
        push(x);
        int m = (l + r) / 2;
        if(y <= m){
                return get(x * 2, l, m, y);
        } else{
                return get(x * 2 + 1, m + 1, r, y);
        }
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        scanf("%d", &n);
        for(int i = 1; i < n; i++){
                scanf("%d%d%d", A + i, B + i, c + i);

                v[A[i]].push_back(i);
                v[B[i]].push_back(i);
        }

        dfs(1, 1);

        g[0] = get(1);
        g[1] = get(g[0][0].se);
        g[2] = get(g[1][0].se);

        int X = g[0][0].se;
        int Y = g[1][0].se;

        for(int i = 1; i < 3; i++){
                for(int j = 0; j < n; j++){
                        iv[g[i][j].se][i] = j;
                }
                g[1].push_back({0, 0});
        }

        build(1, 1, n);

        int q;
        scanf("%d", &q);
        while(q--){
                int i;
                scanf("%d", &i);
                int x = A[i], y = B[i];
                if(l[x] < l[y]){
                        swap(x, y);
                }
                upd(1, 1, n, tin[x], tout[x]);

                int res = 0;
                //cout << f1[1].fi << " " << f1[1].se << " " << f2[1].fi << " " << f2[1].se << "\n";
                if(get(1, 1, n, tin[X])){
                        res = max(res, g[1][f1[1].fi].fi);
                } else{
                        res = max(res, g[1][f2[1].fi].fi);
                }
                if(get(1, 1, n, tin[Y])){
                        res = max(res, g[2][f1[1].se].fi);
                } else{
                        res = max(res, g[2][f2[1].se].fi);
                }

                printf("%d\n", res);
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 500500;

using namespace std;

int n;
int tim;
int A[N];
int B[N];
int c[N];
int l[N];
int d[N];
int id[N];
int tin[N];
int tout[N];
int f[N][20];
vector < int > v[N];

int t1[4 * N];
int t2[4 * N];
int c1[4 * N];
int c2[4 * N];
pair < int, int > p1[4 * N];
pair < int, int > p2[4 * N];
int fl[4 * N];

void dfs(int x, int p)
{
        tin[x] = ++tim;
        f[x][0] = p;
        for(int i = 1; i < 20; i++){
                f[x][i] = f[f[x][i - 1]][i - 1];
        }
        for(int i: v[x]){
                int y = A[i] ^ B[i] ^ x;
                if(y == p){
                        continue;
                }
                l[y] = l[x] + 1;
                d[y] = d[x] ^ c[i];
                dfs(y, x);
        }
        tout[x] = tim;

        id[tin[x]] = x;
}

bool isp(int x, int y)
{
        return tin[x] <= tin[y] && tout[x] >= tout[y];
}

int lca(int x, int y)
{
        if(isp(x, y)){
                return x;
        }
        if(isp(y, x)){
                return y;
        }
        for(int i = 19; i >= 0; i--){
                if(!isp(f[x][i], y)){
                        x = f[x][i];
                }
        }
        return f[x][0];
}

int len(int x, int y)
{
        return l[x] + l[y] - 2 * l[lca(x, y)];
}

void comb(int x)
{
        int l = x * 2, r = x * 2 + 1;
        if(t1[l] > t1[r]){
                t1[x] = t1[l];
                p1[x] = p1[l];
                c1[x] = c1[l];
        } else{
                t1[x] = t1[r];
                p1[x] = p1[r];
                c1[x] = c1[r];
        }
        if(t2[l] > t2[r]){
                t2[x] = t2[l];
                p2[x] = p2[l];
                c2[x] = c2[l];
        } else{
                t2[x] = t2[r];
                p2[x] = p2[r];
                c2[x] = c2[r];
        }
        if(t1[l] != -1 && t1[r] != -1){
                vector < int > v = {c1[l], c1[r], lca(c1[l], c1[r])};
                sort(v.begin(), v.end(), [&](int x, int y){return ::l[x] > ::l[y];});
                int cur, par;
                for(int a: {p1[l].fi, p1[l].se}){
                        for(int b: {p1[r].fi, p1[r].se}){
                                par = 0;
                                while(!isp(v[par], a) || !isp(v[par], b)){
                                        par++;
                                }
                                cur = ::l[a] + ::l[b] - 2 * ::l[v[par]];
                                if(cur > t1[x]){
                                        t1[x] = cur;
                                        p1[x] = {a, b};
                                        c1[x] = v[par];
                                }
                        }
                }
        }

        if(t2[l] != -1 && t2[r] != -1){
                vector < int > v = {c2[l], c2[r], lca(c2[l], c2[r])};
                sort(v.begin(), v.end(), [&](int x, int y){return ::l[x] > ::l[y];});
                int cur, par;
                for(int a: {p2[l].fi, p2[l].se}){
                        for(int b: {p2[r].fi, p2[r].se}){
                                par = 0;
                                while(!isp(v[par], a) || !isp(v[par], b)){
                                        par++;
                                }
                                cur = ::l[a] + ::l[b] - 2 * ::l[v[par]];
                                if(cur > t2[x]){
                                        t2[x] = cur;
                                        p2[x] = {a, b};
                                        c2[x] = v[par];
                                }
                        }
                }
        }
        //cout << x << " " << t2[x] << " " << p2[x].fi << " " << p2[x].se << "\n";
}

void apply(int x)
{
        fl[x] ^= 1;
        swap(t1[x], t2[x]);
        swap(p1[x], p2[x]);
        swap(c1[x], c2[x]);
}

void push(int x)
{
        if(!fl[x]){
                return;
        }
        fl[x] = 0;
        apply(x * 2);
        apply(x * 2 + 1);
}

void build(int x, int l, int r)
{
        t1[x] = t2[x] = c1[x] = c2[x] = -1;
        p1[x] = p2[x] = {-1, -1};
        if(l == r){
                if(d[id[l]]){
                        t1[x] = 0;
                        c1[x] = id[l];
                        p1[x] = {id[l], id[l]};
                } else{
                        t2[x] = 0;
                        c2[x] = id[l];
                        p2[x] = {id[l], id[l]};
                }
                return;
        }
        int m = (l + r) / 2;
        build(x * 2, l, m);
        build(x * 2 + 1, m + 1, r);
        comb(x);
}

void upd(int x, int l, int r, int tl, int tr)
{
        if(tl > tr){
                return;
        } else if(l == tl && r == tr){
                apply(x);
                return;
        }
        push(x);
        int m = (l + r) / 2;
        upd(x * 2, l, m, tl, min(m, tr));
        upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr);
        comb(x);
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        scanf("%d", &n);
        for(int i = 1; i < n; i++){
                scanf("%d%d%d", A + i, B + i, c + i);

                v[A[i]].push_back(i);
                v[B[i]].push_back(i);
        }

        dfs(1, 1);

        build(1, 1, n);

        int q;
        scanf("%d", &q);
        while(q--){
                int i;
                scanf("%d", &i);
                int x = A[i], y = B[i];
                if(l[x] < l[y]){
                        swap(x, y);
                }
                upd(1, 1, n, tin[x], tout[x]);

                printf("%d\n", max(t1[1], t2[1]));
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 500500;

using namespace std;

int n;
int tim;
int A[N];
int B[N];
int c[N];
int l[N];
int d[N];
int id[N];
int tin[N];
int tout[N];
int f[N][20];
vector < int > v[N];

void dfs(int x, int p)
{
        tin[x] = ++tim;
        f[x][0] = p;
        for(int i = 1; i < 20; i++){
                f[x][i] = f[f[x][i - 1]][i - 1];
        }
        for(int i: v[x]){
                int y = A[i] ^ B[i] ^ x;
                if(y == p){
                        continue;
                }
                l[y] = l[x] + 1;
                d[y] = d[x] ^ c[i];
                dfs(y, x);
        }
        tout[x] = tim;

        id[tin[x]] = x;
}

bool isp(int x, int y)
{
        return tin[x] <= tin[y] && tout[x] >= tout[y];
}

int lca(int x, int y)
{
        if(isp(x, y)){
                return x;
        }
        if(isp(y, x)){
                return y;
        }
        for(int i = 19; i >= 0; i--){
                if(!isp(f[x][i], y)){
                        x = f[x][i];
                }
        }
        return f[x][0];
}

int len(int x, int y)
{
        return l[x] + l[y] - 2 * l[lca(x, y)];
}

vector < pair < int, int > >  get(int x)
{
        vector < pair < int, int > > res;
        for(int i = 1; i <= n; i++){
                res.push_back({len(x, i), i});
        }
        sort(res.begin(), res.end());
        reverse(res.begin(), res.end());
        return res;
}

int iv[N][3];
vector < pair < int, int > > g[3];
int fl[4 * N];
pair < int, int > f1[4 * N], f2[4 * N];

void app(int x)
{
        fl[x] ^= 1;
        swap(f1[x], f2[x]);
}

void push(int x)
{
        if(fl[x]){
                fl[x] = 0;
                app(x * 2);
                app(x * 2 + 1);
        }
}

int comb(int x)
{
        f1[x].fi = min(f1[x * 2].fi, f1[x * 2 + 1].fi);
        f1[x].se = min(f1[x * 2].se, f1[x * 2 + 1].se);
        f2[x].fi = min(f2[x * 2].fi, f2[x * 2 + 1].fi);
        f2[x].se = min(f2[x * 2].se, f2[x * 2 + 1].se);
}

void build(int x, int l, int r)
{
        f1[x] = f2[x] = {n, n};
        if(l == r){
                int a = id[l];
                if(d[a]){
                        f1[x] = {iv[a][1], iv[a][2]};
                } else{
                        f2[x] = {iv[a][1], iv[a][2]};
                }
                return;
        }
        int m = (l + r) / 2;
        build(x * 2, l, m);
        build(x * 2 + 1, m + 1, r);
        comb(x);
}

void upd(int x, int l, int r, int tl, int tr)
{
        if(tl > tr){
                return;
        } else if(l == tl && r == tr){
                app(x);
                return;
        }
        push(x);
        int m = (l + r) / 2;
        upd(x  * 2, l, m, tl, min(m, tr));
        upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr);
        comb(x);
}

int get(int x, int l, int r, int y)
{
        if(l == r){
                return d[id[l]] ^ fl[x];
        }
        push(x);
        int m = (l + r) / 2;
        if(y <= m){
                return get(x * 2, l, m, y);
        } else{
                return get(x * 2 + 1, m + 1, r, y);
        }
}

int main()
{
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        scanf("%d", &n);
        for(int i = 1; i < n; i++){
                scanf("%d%d%d", A + i, B + i, c + i);

                v[A[i]].push_back(i);
                v[B[i]].push_back(i);
        }

        dfs(1, 1);

        g[0] = get(1);
        g[1] = get(g[0][0].se);
        g[2] = get(g[1][0].se);

        int X = g[0][0].se;
        int Y = g[1][0].se;

        for(int i = 1; i < 3; i++){
                for(int j = 0; j < n; j++){
                        iv[g[i][j].se][i] = j;
                }
                g[1].push_back({0, 0});
        }

        build(1, 1, n);

        int q;
        scanf("%d", &q);
        while(q--){
                int i;
                scanf("%d", &i);
                int x = A[i], y = B[i];
                if(l[x] < l[y]){
                        swap(x, y);
                }
                upd(1, 1, n, tin[x], tout[x]);

                int res = 0;
                //cout << f1[1].fi << " " << f1[1].se << " " << f2[1].fi << " " << f2[1].se << "\n";
                if(get(1, 1, n, tin[X])){
                        res = max(res, g[1][f1[1].fi].fi);
                } else{
                        res = max(res, g[1][f2[1].fi].fi);
                }
                if(get(1, 1, n, tin[Y])){
                        res = max(res, g[2][f1[1].se].fi);
                } else{
                        res = max(res, g[2][f2[1].se].fi);
                }

                printf("%d\n", res);
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 500500;

using namespace std;

int n;
int tim;
int A[N];
int B[N];
int c[N];
int l[N];
int d[N];
int id[N];
int tin[N];
int tout[N];
int f[N][20];
vector < int > v[N];

int t1[4 * N];
int t2[4 * N];
int c1[4 * N];
int c2[4 * N];
pair < int, int > p1[4 * N];
pair < int, int > p2[4 * N];
int fl[4 * N];

void dfs(int x, int p)
{
        tin[x] = ++tim;
        f[x][0] = p;
        for(int i = 1; i < 20; i++){
                f[x][i] = f[f[x][i - 1]][i - 1];
        }
        for(int i: v[x]){
                int y = A[i] ^ B[i] ^ x;
                if(y == p){
                        continue;
                }
                l[y] = l[x] + 1;
                d[y] = d[x] ^ c[i];
                dfs(y, x);
        }
        tout[x] = tim;

        id[tin[x]] = x;
}

bool isp(int x, int y)
{
        return tin[x] <= tin[y] && tout[x] >= tout[y];
}

int lca(int x, int y)
{
        if(isp(x, y)){
                return x;
        }
        if(isp(y, x)){
                return y;
        }
        for(int i = 19; i >= 0; i--){
                if(!isp(f[x][i], y)){
                        x = f[x][i];
                }
        }
        return f[x][0];
}

int len(int x, int y)
{
        return l[x] + l[y] - 2 * l[lca(x, y)];
}

void comb(int x)
{
        int l = x * 2, r = x * 2 + 1;
        if(t1[l] > t1[r]){
                t1[x] = t1[l];
                p1[x] = p1[l];
                c1[x] = c1[l];
        } else{
                t1[x] = t1[r];
                p1[x] = p1[r];
                c1[x] = c1[r];
        }
        if(t2[l] > t2[r]){
                t2[x] = t2[l];
                p2[x] = p2[l];
                c2[x] = c2[l];
        } else{
                t2[x] = t2[r];
                p2[x] = p2[r];
                c2[x] = c2[r];
        }
        if(t1[l] != -1 && t1[r] != -1){
                vector < int > v = {c1[l], c1[r], lca(c1[l], c1[r])};
                sort(v.begin(), v.end(), [&](int x, int y){return ::l[x] > ::l[y];});
                int a, b, cur, par;
                for(a: {p1[l].fi, p1[l].se}){
                        for(b: {p1[r].fi, p1[r].se}){
                                par = 0;
                                while(!isp(v[par], a) || !isp(v[par], b)){
                                        par++;
                                }
                                cur = ::l[a] + ::l[b] - 2 * ::l[v[par]];
                                if(cur > t1[x]){
                                        t1[x] = cur;
                                        p1[x] = {a, b};
                                        c1[x] = v[par];
                                }
                        }
                }
        }

        if(t2[l] != -1 && t2[r] != -1){
                vector < int > v = {c2[l], c2[r], lca(c2[l], c2[r])};
                sort(v.begin(), v.end(), [&](int x, int y){return ::l[x] > ::l[y];});
                int a, b, cur, par;
                for(a: {p2[l].fi, p2[l].se}){
                        for(b: {p2[r].fi, p2[r].se}){
                                par = 0;
                                while(!isp(v[par], a) || !isp(v[par], b)){
                                        par++;
                                }
                                cur = ::l[a] + ::l[b] - 2 * ::l[v[par]];
                                if(cur > t2[x]){
                                        t2[x] = cur;
                                        p2[x] = {a, b};
                                        c2[x] = v[par];
                                }
                        }
                }
        }
        //cout << x << " " << t2[x] << " " << p2[x].fi << " " << p2[x].se << "\n";
}

void apply(int x)
{
        fl[x] ^= 1;
        swap(t1[x], t2[x]);
        swap(p1[x], p2[x]);
        swap(c1[x], c2[x]);
}

void push(int x)
{
        if(!fl[x]){
                return;
        }
        fl[x] = 0;
        apply(x * 2);
        apply(x * 2 + 1);
}

void build(int x, int l, int r)
{
        t1[x] = t2[x] = c1[x] = c2[x] = -1;
        p1[x] = p2[x] = {-1, -1};
        if(l == r){
                if(d[id[l]]){
                        t1[x] = 0;
                        c1[x] = id[l];
                        p1[x] = {id[l], id[l]};
                } else{
                        t2[x] = 0;
                        c2[x] = id[l];
                        p2[x] = {id[l], id[l]};
                }
                return;
        }
        int m = (l + r) / 2;
        build(x * 2, l, m);
        build(x * 2 + 1, m + 1, r);
        comb(x);
}

void upd(int x, int l, int r, int tl, int tr)
{
        if(tl > tr){
                return;
        } else if(l == tl && r == tr){
                apply(x);
                return;
        }
        push(x);
        int m = (l + r) / 2;
        upd(x * 2, l, m, tl, min(m, tr));
        upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr);
        comb(x);
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        scanf("%d", &n);
        for(int i = 1; i < n; i++){
                scanf("%d%d%d", A + i, B + i, c + i);

                v[A[i]].push_back(i);
                v[B[i]].push_back(i);
        }

        dfs(1, 1);

        build(1, 1, n);

        int q;
        scanf("%d", &q);
        while(q--){
                int i;
                scanf("%d", &i);
                int x = A[i], y = B[i];
                if(l[x] < l[y]){
                        swap(x, y);
                }
                upd(1, 1, n, tin[x], tout[x]);

                printf("%d\n", max(t1[1], t2[1]));
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 500500;

using namespace std;

int n;
int tim;
int A[N];
int B[N];
int c[N];
int l[N];
int d[N];
int id[N];
int tin[N];
int tout[N];
int f[N][20];
vector < int > v[N];

int t1[4 * N];
int t2[4 * N];
int c1[4 * N];
int c2[4 * N];
pair < int, int > p1[4 * N];
pair < int, int > p2[4 * N];
int fl[4 * N];

void dfs(int x, int p)
{
        tin[x] = ++tim;
        f[x][0] = p;
        for(int i = 1; i < 20; i++){
                f[x][i] = f[f[x][i - 1]][i - 1];
        }
        for(int i: v[x]){
                int y = A[i] ^ B[i] ^ x;
                if(y == p){
                        continue;
                }
                l[y] = l[x] + 1;
                d[y] = d[x] ^ c[i];
                dfs(y, x);
        }
        tout[x] = tim;

        id[tin[x]] = x;
}

bool isp(int x, int y)
{
        return tin[x] <= tin[y] && tout[x] >= tout[y];
}

int lca(int x, int y)
{
        if(isp(x, y)){
                return x;
        }
        if(isp(y, x)){
                return y;
        }
        for(int i = 19; i >= 0; i--){
                if(!isp(f[x][i], y)){
                        x = f[x][i];
                }
        }
        return f[x][0];
}

int len(int x, int y)
{
        return l[x] + l[y] - 2 * l[lca(x, y)];
}

void comb(int x)
{
        int l = x * 2, r = x * 2 + 1;
        if(t1[l] > t1[r]){
                t1[x] = t1[l];
                p1[x] = p1[l];
                c1[x] = c1[l];
        } else{
                t1[x] = t1[r];
                p1[x] = p1[r];
                c1[x] = c1[r];
        }
        if(t2[l] > t2[r]){
                t2[x] = t2[l];
                p2[x] = p2[l];
                c2[x] = c2[l];
        } else{
                t2[x] = t2[r];
                p2[x] = p2[r];
                c2[x] = c2[r];
        }
        if(t1[l] != -1 && t1[r] != -1){
                vector < int > v = {c1[l], c1[r], lca(c1[l], c1[r])};
                sort(v.begin(), v.end(), [&](int x, int y){return ::l[x] > ::l[y];});
                int cur, par;
                for(int a: {p1[l].fi, p1[l].se}){
                        for(int b: {p1[r].fi, p1[r].se}){
                                par = 0;
                                while(!isp(v[par], a) || !isp(v[par], b)){
                                        par++;
                                }
                                par = v[par];
                                if(isp(a, b)) par = a;
                                if(isp(b, a)) par = b;
                                cur = ::l[a] + ::l[b] - 2 * ::l[par];
                                if(cur > t1[x]){
                                        t1[x] = cur;
                                        p1[x] = {a, b};
                                        c1[x] = par;
                                }
                                //assert(lca(a, b) == par);
                        }
                }
        }

        if(t2[l] != -1 && t2[r] != -1){
                vector < int > v = {c2[l], c2[r], lca(c2[l], c2[r])};
                sort(v.begin(), v.end(), [&](int x, int y){return ::l[x] > ::l[y];});
                int cur, par;
                for(int a: {p2[l].fi, p2[l].se}){
                        for(int b: {p2[r].fi, p2[r].se}){
                                par = 0;
                                while(!isp(v[par], a) || !isp(v[par], b)){
                                        par++;
                                }
                                par = v[par];
                                if(isp(a, b)) par = a;
                                if(isp(b, a)) par = b;
                                cur = ::l[a] + ::l[b] - 2 * ::l[par];
                                if(cur > t2[x]){
                                        t2[x] = cur;
                                        p2[x] = {a, b};
                                        c2[x] = par;
                                }
                                //assert(lca(a, b) == par);
                        }
                }
        }
        //cout << x << " " << t2[x] << " " << p2[x].fi << " " << p2[x].se << "\n";
}

void apply(int x)
{
        fl[x] ^= 1;
        swap(t1[x], t2[x]);
        swap(p1[x], p2[x]);
        swap(c1[x], c2[x]);
}

void push(int x)
{
        if(!fl[x]){
                return;
        }
        fl[x] = 0;
        apply(x * 2);
        apply(x * 2 + 1);
}

void build(int x, int l, int r)
{
        t1[x] = t2[x] = c1[x] = c2[x] = -1;
        p1[x] = p2[x] = {-1, -1};
        if(l == r){
                if(d[id[l]]){
                        t1[x] = 0;
                        c1[x] = id[l];
                        p1[x] = {id[l], id[l]};
                } else{
                        t2[x] = 0;
                        c2[x] = id[l];
                        p2[x] = {id[l], id[l]};
                }
                return;
        }
        int m = (l + r) / 2;
        build(x * 2, l, m);
        build(x * 2 + 1, m + 1, r);
        comb(x);
}

void upd(int x, int l, int r, int tl, int tr)
{
        if(tl > tr){
                return;
        } else if(l == tl && r == tr){
                apply(x);
                return;
        }
        push(x);
        int m = (l + r) / 2;
        upd(x * 2, l, m, tl, min(m, tr));
        upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr);
        comb(x);
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        scanf("%d", &n);
        for(int i = 1; i < n; i++){
                scanf("%d%d%d", A + i, B + i, c + i);

                v[A[i]].push_back(i);
                v[B[i]].push_back(i);
        }

        dfs(1, 1);

        build(1, 1, n);

        int q;
        scanf("%d", &q);
        while(q--){
                int i;
                scanf("%d", &i);
                int x = A[i], y = B[i];
                if(l[x] < l[y]){
                        swap(x, y);
                }
                upd(1, 1, n, tin[x], tout[x]);

                printf("%d\n", max(t1[1], t2[1]));
        }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 500500;

using namespace std;

int n;
int tim;
int A[N];
int B[N];
int c[N];
int l[N];
int d[N];
int id[N];
int tin[N];
int tout[N];
int f[N][20];
vector < int > v[N];

int t1[4 * N];
int t2[4 * N];
int c1[4 * N];
int c2[4 * N];
pair < int, int > p1[4 * N];
pair < int, int > p2[4 * N];
int fl[4 * N];

void dfs(int x, int p)
{
        tin[x] = ++tim;
        f[x][0] = p;
        for(int i = 1; i < 20; i++){
                f[x][i] = f[f[x][i - 1]][i - 1];
        }
        for(int i: v[x]){
                int y = A[i] ^ B[i] ^ x;
                if(y == p){
                        continue;
                }
                l[y] = l[x] + 1;
                d[y] = d[x] ^ c[i];
                dfs(y, x);
        }
        tout[x] = tim;

        id[tin[x]] = x;
}

bool isp(int x, int y)
{
        return tin[x] <= tin[y] && tout[x] >= tout[y];
}

int lca(int x, int y)
{
        if(isp(x, y)){
                return x;
        }
        if(isp(y, x)){
                return y;
        }
        for(int i = 19; i >= 0; i--){
                if(!isp(f[x][i], y)){
                        x = f[x][i];
                }
        }
        return f[x][0];
}

int len(int x, int y)
{
        return l[x] + l[y] - 2 * l[lca(x, y)];
}

void comb(int x)
{
        int l = x * 2, r = x * 2 + 1;
        if(t1[l] > t1[r]){
                t1[x] = t1[l];
                p1[x] = p1[l];
                c1[x] = c1[l];
        } else{
                t1[x] = t1[r];
                p1[x] = p1[r];
                c1[x] = c1[r];
        }
        if(t2[l] > t2[r]){
                t2[x] = t2[l];
                p2[x] = p2[l];
                c2[x] = c2[l];
        } else{
                t2[x] = t2[r];
                p2[x] = p2[r];
                c2[x] = c2[r];
        }
        if(t1[l] != -1 && t1[r] != -1){
                vector < int > v = {c1[l], c1[r], lca(p1[l].se, p1[r].fi)};
                sort(v.begin(), v.end(), [&](int x, int y){return ::l[x] > ::l[y];});
                int cur, par;
                for(int a: {p1[l].fi, p1[l].se}){
                        for(int b: {p1[r].fi, p1[r].se}){
                                par = 0;
                                while(!isp(v[par], a) || !isp(v[par], b)){
                                        par++;
                                }
                                par = v[par];
                                if(isp(a, b)) par = a;
                                if(isp(b, a)) par = b;
                                cur = ::l[a] + ::l[b] - 2 * ::l[par];
                                if(cur > t1[x]){
                                        t1[x] = cur;
                                        p1[x] = {a, b};
                                        c1[x] = par;
                                }
                                //assert(lca(a, b) == par);
                        }
                }
        }

        if(t2[l] != -1 && t2[r] != -1){
                vector < int > v = {c2[l], c2[r], lca(p2[l].se, p2[r].fi)};
                sort(v.begin(), v.end(), [&](int x, int y){return ::l[x] > ::l[y];});
                int cur, par;
                for(int a: {p2[l].fi, p2[l].se}){
                        for(int b: {p2[r].fi, p2[r].se}){
                                par = 0;
                                while(!isp(v[par], a) || !isp(v[par], b)){
                                        par++;
                                }
                                par = v[par];
                                if(isp(a, b)) par = a;
                                if(isp(b, a)) par = b;
                                cur = ::l[a] + ::l[b] - 2 * ::l[par];
                                if(cur > t2[x]){
                                        t2[x] = cur;
                                        p2[x] = {a, b};
                                        c2[x] = par;
                                }
                                //assert(lca(a, b) == par);
                        }
                }
        }
        //cout << x << " " << t2[x] << " " << p2[x].fi << " " << p2[x].se << "\n";
}

void apply(int x)
{
        fl[x] ^= 1;
        swap(t1[x], t2[x]);
        swap(p1[x], p2[x]);
        swap(c1[x], c2[x]);
}

void push(int x)
{
        if(!fl[x]){
                return;
        }
        fl[x] = 0;
        apply(x * 2);
        apply(x * 2 + 1);
}

void build(int x, int l, int r)
{
        t1[x] = t2[x] = c1[x] = c2[x] = -1;
        p1[x] = p2[x] = {-1, -1};
        if(l == r){
                if(d[id[l]]){
                        t1[x] = 0;
                        c1[x] = id[l];
                        p1[x] = {id[l], id[l]};
                } else{
                        t2[x] = 0;
                        c2[x] = id[l];
                        p2[x] = {id[l], id[l]};
                }
                return;
        }
        int m = (l + r) / 2;
        build(x * 2, l, m);
        build(x * 2 + 1, m + 1, r);
        comb(x);
}

void upd(int x, int l, int r, int tl, int tr)
{
        if(tl > tr){
                return;
        } else if(l == tl && r == tr){
                apply(x);
                return;
        }
        push(x);
        int m = (l + r) / 2;
        upd(x * 2, l, m, tl, min(m, tr));
        upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr);
        comb(x);
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        scanf("%d", &n);
        for(int i = 1; i < n; i++){
                scanf("%d%d%d", A + i, B + i, c + i);

                v[A[i]].push_back(i);
                v[B[i]].push_back(i);
        }

        dfs(1, 1);

        build(1, 1, n);

        int q;
        scanf("%d", &q);
        while(q--){
                int i;
                scanf("%d", &i);
                int x = A[i], y = B[i];
                if(l[x] < l[y]){
                        swap(x, y);
                }
                upd(1, 1, n, tin[x], tout[x]);

                printf("%d\n", max(t1[1], t2[1]));
        }
}


#include<bits/stdc++.h>
/*
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<cctype>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
*/
//#pragma GCC optimize(2)
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef pair<double,double> pdd;
const int N=5e5+5;
const int M=8e5+5;
const int inf=0x3f3f3f3f;
const LL mod=1e8+7;
const double eps=1e-8;
const long double pi=acos(-1.0L);
#define ls (i<<1)
#define rs (i<<1|1)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
LL read()
{
    LL x=0,t=1;
    char ch;
    while(!isdigit(ch=getchar())) if(ch=='-') t=-1;
    while(isdigit(ch)){ x=10*x+ch-'0'; ch=getchar(); }
    return x*t;

}
vector<pii> e[N];
struct edge{int u,v,w;}a[N];
int rt1,rt2,ma;
pii ma1[N],ma2[N];
//建两颗树（一棵树需要c、lz、int、out、rk、deep数组；如果直接用数组名传参，参数表就太长了，不如直接做一个结构体）
struct node
{
    int c[N<<2][2],lz[N<<2],in[N],out[N],rk[N],dep[N],col[N],tot;
    inline void pushdown(int i)
    {
        swap(c[ls][0],c[ls][1]);
        swap(c[rs][0],c[rs][1]);
        lz[ls]^=1; lz[rs]^=1;
        lz[i]=0;
    }
    inline void pushup(int i)
    {
        c[i][0]=max(c[ls][0],c[rs][0]);
        c[i][1]=max(c[ls][1],c[rs][1]);
    }
    void build(int i,int l,int r)
    {
        c[i][0]=c[i][1]=lz[i]=0;
        if(l==r) return (void)(c[i][col[rk[l]]]=dep[rk[l]]);
        int mid=l+r>>1;
        build(ls,l,mid);
        build(rs,mid+1,r);
        pushup(i);
    }
    void update(int i,int l,int r,int ll,int rr)
    {
        if(ll<=l&&r<=rr) return (void)(swap(c[i][0],c[i][1]),lz[i]^=1);
        int mid=l+r>>1;
        if(lz[i]) pushdown(i);
        if(mid>=ll) update(ls,l,mid,ll,rr);
        if(mid<rr) update(rs,mid+1,r,ll,rr);
        pushup(i);
    }

    void dfs(int u,int pre)
    {
        in[u]=++tot; rk[tot]=u;
        dep[u]=dep[pre]+1;
        for(auto x:e[u])
        {
            int v=x.fi,w=x.se;
            if(v==pre) continue;
            col[v]=col[u]^w;
            dfs(v,u);
        }
        out[u]=tot;
    }
}tr[2];
void dfs2(int u,int pre)
{
    ma1[u]=ma2[u]=mk(0,u);
    for(auto x:e[u])
    {
        int v=x.fi;
        if(v==pre) continue;
        dfs2(v,u);
        pii t=ma1[v];
        if(t>ma1[u]) swap(t,ma1[u]);
        if(t>ma2[u]) ma2[u]=t;
        //f[u]=max(f[v],f[u]);
    }
    //printf("u = %d , fi = %d , se = %d\n",u,ma1[u].fi,ma2[u].fi);
    if(ma1[u].fi+ma2[u].fi>ma) ma=ma1[u].fi+ma2[u].fi,rt1=ma1[u].se,rt2=ma2[u].se;
    ma1[u].fi++; ma2[u].fi++;
}

int main()
{
    int n=read();
    for(int i=1;i<n;i++)
    {
        int x=read(),y=read(),z=read();
        a[i]=edge{x,y,z};
        e[x].eb(y,z);
        e[y].eb(x,z);
    }
    dfs2(1,0);
   // printf("%d %d\n",rt1,rt2);
    tr[0].dfs(rt1,0);
    tr[0].build(1,1,n);
    tr[1].dfs(rt2,0);
    tr[1].build(1,1,n);
    int m=read();
    for(int i=1;i<=m;i++)
    {
        int x=read(),y=a[x].u;
        if(tr[0].dep[a[x].u]<tr[0].dep[a[x].v]) y=a[x].v;
        tr[0].update(1,1,n,tr[0].in[y],tr[0].out[y]);
        y=a[x].u;
        if(tr[1].dep[a[x].u]<tr[1].dep[a[x].v]) y=a[x].v;
        tr[1].update(1,1,n,tr[1].in[y],tr[1].out[y]);
        printf("%d\n",max(tr[0].c[1][0],tr[1].c[1][0])-1);
    }
    return 0;
}


#include<bits/stdc++.h>
/*
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<cctype>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
*/
//#pragma GCC optimize(2)
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef pair<double,double> pdd;
const int N=2e5+5;
const int M=8e5+5;
const int inf=0x3f3f3f3f;
const LL mod=1e8+7;
const double eps=1e-8;
const long double pi=acos(-1.0L);
#define ls (i<<1)
#define rs (i<<1|1)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
LL read()
{
    LL x=0,t=1;
    char ch;
    while(!isdigit(ch=getchar())) if(ch=='-') t=-1;
    while(isdigit(ch)){ x=10*x+ch-'0'; ch=getchar(); }
    return x*t;

}
vector<pii> e[N];
struct edge{int u,v,w;}a[N];
int rt1,rt2,ma;
pii ma1[N],ma2[N];
//建两颗树（一棵树需要c、lz、int、out、rk、deep数组；如果直接用数组名传参，参数表就太长了，不如直接做一个结构体）
struct node
{
    int c[N<<2][2],lz[N<<2],in[N],out[N],rk[N],dep[N],col[N],tot;
    inline void pushdown(int i)
    {
        swap(c[ls][0],c[ls][1]);
        swap(c[rs][0],c[rs][1]);
        lz[ls]^=1; lz[rs]^=1;
        lz[i]=0;
    }
    inline void pushup(int i)
    {
        c[i][0]=max(c[ls][0],c[rs][0]);
        c[i][1]=max(c[ls][1],c[rs][1]);
    }
    void build(int i,int l,int r)
    {
        c[i][0]=c[i][1]=lz[i]=0;
        if(l==r) return (void)(c[i][col[rk[l]]]=dep[rk[l]]);
        int mid=l+r>>1;
        build(ls,l,mid);
        build(rs,mid+1,r);
        pushup(i);
    }
    void update(int i,int l,int r,int ll,int rr)
    {
        if(ll<=l&&r<=rr) return (void)(swap(c[i][0],c[i][1]),lz[i]^=1);
        int mid=l+r>>1;
        if(lz[i]) pushdown(i);
        if(mid>=ll) update(ls,l,mid,ll,rr);
        if(mid<rr) update(rs,mid+1,r,ll,rr);
        pushup(i);
    }

    void dfs(int u,int pre)
    {
        in[u]=++tot; rk[tot]=u;
        dep[u]=dep[pre]+1;
        for(auto x:e[u])
        {
            int v=x.fi,w=x.se;
            if(v==pre) continue;
            col[v]=col[u]^w;
            dfs(v,u);
        }
        out[u]=tot;
    }
}tr[2];
void dfs2(int u,int pre)
{
    ma1[u]=ma2[u]=mk(0,u);
    for(auto x:e[u])
    {
        int v=x.fi;
        if(v==pre) continue;
        dfs2(v,u);
        pii t=ma1[v];
        if(t>ma1[u]) swap(t,ma1[u]);
        if(t>ma2[u]) ma2[u]=t;
        //f[u]=max(f[v],f[u]);
    }
    //printf("u = %d , fi = %d , se = %d\n",u,ma1[u].fi,ma2[u].fi);
    if(ma1[u].fi+ma2[u].fi>ma) ma=ma1[u].fi+ma2[u].fi,rt1=ma1[u].se,rt2=ma2[u].se;
    ma1[u].fi++; ma2[u].fi++;
}

int main()
{
    int n=read();
    for(int i=1;i<n;i++)
    {
        int x=read(),y=read(),z=read();
        a[i]=edge{x,y,z};
        e[x].eb(y,z);
        e[y].eb(x,z);
    }
    dfs2(1,0);
   // printf("%d %d\n",rt1,rt2);
    tr[0].dfs(rt1,0);
    tr[0].build(1,1,n);
    tr[1].dfs(rt2,0);
    tr[1].build(1,1,n);
    int m=read();
    for(int i=1;i<=m;i++)
    {
        int x=read(),y=a[x].u;
        if(tr[0].dep[a[x].u]<tr[0].dep[a[x].v]) y=a[x].v;
        tr[0].update(1,1,n,tr[0].in[y],tr[0].out[y]);
        y=a[x].u;
        if(tr[1].dep[a[x].u]<tr[1].dep[a[x].v]) y=a[x].v;
        tr[1].update(1,1,n,tr[1].in[y],tr[1].out[y]);
        printf("%d\n",max(tr[0].c[1][0],tr[1].c[1][0])-1);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 50;

struct Edge{
	int x, y, t;
}e[N];

struct Tree{
	int v[2], c, lazy;
}tree1[N << 2], tree2[N << 2];

vector<int> g[N], h[N];
int nowl, nowp, n, root, root1, cnt1, cnt2;
int fa[N], fa1[N], fa2[N];
int st1[N], st2[N], ed1[N], ed2[N];

inline void add(int x, int y) {
	g[x].push_back(y);
	g[y].push_back(x);
}

void dfs(int x, int deep) {
	if(deep > nowl) {
		nowp = x;
		nowl = deep;
	}
	for(int i = 0; i < g[x].size(); i++) {
		int y = g[x][i];
		if(y == fa[x])continue;
		fa[y] = x;
		dfs(y, deep + 1);
	}
}

void update(Tree *tree, int k) {
	for(int i = 0; i < 2; i++)
		tree[k].v[i] = max(tree[k << 1].v[i], tree[k << 1 | 1].v[i]);
}

void add(Tree *tree, int k, int l, int r, int ll, int c, int v) {
	if(l == r) {
		tree[k].v[c] = v;
		return;
	}
	int mid = (l + r) >> 1;
	if(mid >= ll)add(tree, k << 1, l, mid, ll, c, v);
	else add(tree, k << 1 | 1, mid + 1, r, ll, c, v);
	update(tree, k);
}

void work(int x, int c, int *fa, Tree *tree, int deep, int *st, int *ed, int &cnt) {
	st[x] = ++cnt;
	add(tree, 1, 1, n, st[x], c, deep);
	for(int i = 0; i < g[x].size(); i++) {
		int y = g[x][i];
		if(y == fa[x])continue;
		int num = h[x][i];
		fa[y] = x;
		work(y, c ^ e[num].t, fa, tree, deep + 1, st, ed, cnt);
	}
	ed[x] = cnt;
}

void down(Tree *tree, int k) {
	if(!tree[k].lazy)return;
	tree[k << 1].lazy ^= 1;
	swap(tree[k << 1].v[0], tree[k << 1].v[1]);
	tree[k << 1 | 1].lazy ^= 1;
	swap(tree[k << 1 | 1].v[0], tree[k << 1 | 1].v[1]);
	tree[k].lazy = 0;
}

void modify(Tree *tree, int k, int l, int r, int ll, int rr) {
	if(ll <= l && r <= rr) {
		tree[k].lazy ^= 1;
		swap(tree[k].v[0], tree[k].v[1]);
		return;
	}
	down(tree, k);
	int mid = (l + r) >> 1;
	if(mid >= ll)modify(tree, k << 1, l, mid, ll, rr);
	if(mid < rr)modify(tree, k << 1 | 1, mid + 1, r, ll, rr);
	update(tree, k);
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].t);
		add(e[i].x, e[i].y);
		h[e[i].x].push_back(i);
		h[e[i].y].push_back(i);
	}
	dfs(1, 0);
	nowl = 0;
	root = nowp;
	fa[root] = 0;
	dfs(root, 0);
	root1 = nowp;
	work(root, 0, fa1, tree1, 0, st1, ed1, cnt1);
	work(root1, 0, fa2, tree2, 0, st2, ed2, cnt2);
	int m;
	scanf("%d", &m);
	for(int i = 1; i <= m; i++) {
		int cnt;
		scanf("%d", &cnt);
		int x = e[cnt].x, y = e[cnt].y;
		if(fa1[y] == x)swap(x, y);
		modify(tree1, 1, 1, n, st1[x], ed1[x]);
		if(fa2[y] == x)swap(x, y);
		modify(tree2, 1, 1, n, st2[x], ed2[x]);
		printf("%d\n", max(tree1[1].v[0], tree2[1].v[0]));
	}
}


// Why is it so hard to get over it?
#include<bits/stdc++.h>
#define pb push_back
#define lc (id << 1)
#define rc (lc ^ 1)
#define md (l + r >> 1)
using namespace std;
typedef long long ll;
const int N = 5e5 + 10, MXS = N * 8, Mod = 1e9 + 7;
struct Data {int a, b, ab, bc, abc;};
int n, q, ts, St[N], Fn[N], H[N], A[N * 2], W[N], LZ[MXS];
Data D[MXS][2];
vector < pair < int , int > > Adj[N];
inline void Merge(int id)
{
    LZ[id] = 0;
    for (int w = 0; w <= 1; w ++)
    {
        Data &d = D[id][w];
        Data &l = D[lc][w];
        Data &r = D[rc][w];
        d.a = max(l.a, r.a);
        d.b = min(l.b, r.b);
        d.ab = max({l.ab, r.ab, l.a - r.b * 2});
        d.bc = max({l.bc, r.bc, r.a - l.b * 2});
        d.abc = max({l.abc, r.abc, l.a + r.bc, l.ab + r.a});
    }
}
void Build(int id = 1, int l = 0, int r = ts)
{
    if (r - l < 2)
    {
        D[id][0].a = A[l];
        D[id][0].b = A[l];
        D[id][0].ab = 0;
        D[id][0].bc = 0;
        D[id][0].abc = 0;
        D[id][1] = {-Mod, A[l], -Mod, -Mod, 0};
        LZ[id] = 0;
        return ;
    }
    Build(lc, l, md);
    Build(rc, md, r);
    Merge(id);
}
inline void Update(int id)
{
    swap(D[id][0], D[id][1]);
    LZ[id] ^= 1;
}
inline void Shift(int id)
{
    if (!LZ[id])
        return ;
    Update(lc);
    Update(rc);
    LZ[id] = 0;
}
void Add(int le, int ri, int id = 1, int l = 0, int r = ts)
{
    if (ri <= l || r <= le)
        return ;
    if (le <= l && r <= ri)
        return void(Update(id));
    Shift(id);
    Add(le, ri, lc, l, md);
    Add(le, ri, rc, md, r);
    Merge(id);
}
void DFS(int v, int p)
{
    for (auto u : Adj[v])
        if (u.first != p)
        {
            H[u.first] = H[v] + 1;
            St[u.second] = ++ ts;
            A[ts] = H[u.first];
            DFS(u.first, v);
            Fn[u.second] = ++ ts;
            A[ts] = H[v];
        }
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i < n; i ++)
    {
        int v, u;
        scanf("%d%d%d", &v, &u, &W[i]);
        Adj[v].pb({u, i});
        Adj[u].pb({v, i});
    }
    DFS(1, 0);
    Build();
    for (int i = 1; i < n; i ++)
        if (W[i])
            Add(St[i], Fn[i]);
    scanf("%d", &q);
    for (; q; q --)
    {
        int i;
        scanf("%d", &i);
        Add(St[i], Fn[i]);
        W[i] ^= 1;
        printf("%d\n", max(D[1][0].abc, D[1][1].abc));
    }
    return 0;
}


// Why is it so hard to get over it?
#include<bits/stdc++.h>
#define pb push_back
#define lc (id << 1)
#define rc (lc ^ 1)
#define md (l + r >> 1)
using namespace std;
typedef long long ll;
const int N = 5e5 + 10, MXS = N * 8, Mod = 1e8 + 7;
struct Data {int a, b, ab, bc, abc;};
int n, q, ts, St[N], Fn[N], H[N], A[N * 2], W[N], LZ[MXS];
Data D[MXS][2];
vector < pair < int , int > > Adj[N];
inline void Merge(int id)
{
    LZ[id] = 0;
    for (int w = 0; w <= 1; w ++)
    {
        Data &d = D[id][w];
        Data &l = D[lc][w];
        Data &r = D[rc][w];
        d.a = max(l.a, r.a);
        d.b = min(l.b, r.b);
        d.ab = max({l.ab, r.ab, l.a - r.b * 2});
        d.bc = max({l.bc, r.bc, r.a - l.b * 2});
        d.abc = max({l.abc, r.abc, l.a + r.bc, l.ab + r.a});
    }
}
void Build(int id = 1, int l = 0, int r = ts)
{
    if (r - l < 2)
    {
        D[id][0].a = A[l];
        D[id][0].b = A[l];
        D[id][0].ab = -A[l];
        D[id][0].bc = -A[l];
        D[id][0].abc = 0;
        D[id][1] = {-Mod, A[l], -Mod, -Mod, 0};
        LZ[id] = 0;
        return ;
    }
    Build(lc, l, md);
    Build(rc, md, r);
    Merge(id);
}
inline void Update(int id)
{
    swap(D[id][0], D[id][1]);
    LZ[id] ^= 1;
}
inline void Shift(int id)
{
    if (!LZ[id])
        return ;
    Update(lc);
    Update(rc);
    LZ[id] = 0;
}
void Add(int le, int ri, int id = 1, int l = 0, int r = ts)
{
    if (ri <= l || r <= le)
        return ;
    if (le <= l && r <= ri)
        return void(Update(id));
    Shift(id);
    Add(le, ri, lc, l, md);
    Add(le, ri, rc, md, r);
    Merge(id);
}
void DFS(int v, int p)
{
    for (auto u : Adj[v])
        if (u.first != p)
        {
            H[u.first] = H[v] + 1;
            St[u.second] = ++ ts;
            A[ts] = H[u.first];
            DFS(u.first, v);
            Fn[u.second] = ++ ts;
            A[ts] = H[v];
        }
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i < n; i ++)
    {
        int v, u;
        scanf("%d%d%d", &v, &u, &W[i]);
        Adj[v].pb({u, i});
        Adj[u].pb({v, i});
    }
    DFS(1, 0);
    Build();
    for (int i = 1; i < n; i ++)
        if (W[i])
            Add(St[i], Fn[i]);
    scanf("%d", &q);
    for (; q; q --)
    {
        int i;
        scanf("%d", &i);
        Add(St[i], Fn[i]);
        W[i] ^= 1;
        printf("%d\n", max({D[1][0].abc, D[1][1].abc, 0}));
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 500016
#define SZ (1<<20)

int et[N];
vpii adj[N];

struct Tree {
    int n = 0;
    int ord[N];
    int lvl[N];
    int epar[N];
    int vl[N], vr[N], vt[N];

    bool lazy[SZ];
    int hi[SZ][2];

    void preorder(int u, int p = 0)
    {
        ord[n] = u;
        vl[u] = n++;
        for (const pii &e : adj[u]) {
            int v = e.fir, i = e.sec;
            ctif(v == p);
            lvl[v] = lvl[u]+1;
            vt[v] = vt[u]^et[i];
            epar[i] = v;
            preorder(v, u);
        }
        vr[u] = n;
    }
    void build(int u, int b, int e )
    {
        if (b+1 == e) {
            int v = ord[b];
            hi[u][vt[v]] = lvl[v];
            return;
        }
        int m = (b+e)/2, lc = 2*u, rc = 2*u+1;
        build(lc, b, m);
        build(rc, m, e);
        for (int j : {0, 1}) hi[u][j] = max(hi[lc][j], hi[rc][j]);
    }
    void push(int u)
    {
        lazy[u] ^= 1;
        swap(hi[u][0], hi[u][1]);
    }
    void flip(int u, int b, int e, int l, int r)
    {
        retif(b >= r || l >= e);
        retif(b >= l && r >= e) push(u);
        int m = (b+e)/2, lc = 2*u, rc = 2*u+1;
        if (lazy[u]) {
            push(lc);
            push(rc);
            lazy[u] = 0;
        }
        flip(lc, b, m, l, r);
        flip(rc, m, e, l, r);
        for (int j : {0, 1}) hi[u][j] = max(hi[lc][j], hi[rc][j]);
    }
    void flip_edge(int i)
    {
        int v = epar[i];
        flip(1, 0, n, vl[v], vr[v]);
    }
};

Tree tree[2];

pii far(int u, int p = 0)
{
    pii res(-1, u);
    for (const pii &e : adj[u]) {
        int v = e.fir;
        ctif(v == p);
        res = max(res, far(v, u));
    }
    ++res.fir;
    return res;
}

int main()
{
    canhazfast();

    int n, m;
    int s[2];

    cin >> n;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v >> et[i];
        adj[u].empb(v, i);
        adj[v].empb(u, i);
    }
    s[0] = far(1).sec;
    s[1] = far(s[0]).sec;
    for (int j : {0, 1}) {
        tree[j].preorder(s[j]);
        tree[j].build(1, 0, n);
        /*cerr << "j = " << j << '\n';
        cerr << "  s = " << s[j] << '\n';
        cerr << "  preorder:"; for (int i = 0; i < n; ++i) cerr << ' ' << tree[j].ord[i]; cerr << '\n';*/
    }

    cin >> m;
    for (int i = 0; i < m; ++i) {
        int id, res = 0;
        cin >> id;
        for (int j : {0, 1}) {
            tree[j].flip_edge(id);
            res = max(res, tree[j].hi[1][0]);
        }
        cout << res << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair < int , int > pii;
#define fi first
#define se second
#define mp make_pair

const int MN = 5e5 + 5;

struct node { int val[2]; } T[MN << 2];
node operator + (node a , node b) {
	return (node) {max(a.val[0] , b.val[0]) , max(a.val[1] , b.val[1])};
}

int N , M , idx[MN] , ans[MN] , fa[MN] , dep[MN] , rt;
vector < pii > a[MN];
vector < pii > G;

inline void chkmax(int &x , int y) {
	x = max(x , y);
}

struct sol {
	int f[MN] , l[MN] , siz , r[MN] , rev[MN] , tg[MN << 2] , dep[MN] , fa[MN];
	inline void dfs(int x) {
		rev[l[x] = ++siz] = x;
		for (auto o : a[x]) {
			if (o.fi == fa[x]) continue; int y = o.fi;
			fa[y] = x , dep[y] = dep[x] + 1; f[y] = (f[x] + o.se) & 1; dfs(y);
		}
		r[x] = siz;
	}
	inline void build(int idx , int l , int r) {
		tg[idx] = 0;
		if (l == r) {
			T[idx].val[f[rev[l]]] = dep[rev[l]]; T[idx].val[f[rev[l]] ^ 1] = 0;
			return;
		}
		int mid = l + r >> 1;
		build(idx << 1 , l , mid) , build(idx << 1 | 1 , mid + 1 , r);
		T[idx] = T[idx << 1] + T[idx << 1 | 1];
	}
	inline void R(int o) {
		swap(T[o].val[0] , T[o].val[1]); tg[o] ^= 1;
	}
	inline void pushdown(int o) {
		if (tg[o]) R(o << 1) , R(o << 1 | 1) , tg[o] = 0;
	}
	inline void modify(int now , int l , int r , int ql , int qr) {
		if (l == ql && r == qr) return R(now);
		int mid = l + r >> 1; pushdown(now);
		if (mid >= qr) modify(now << 1 , l , mid , ql , qr);
		else if (mid + 1 <= ql) modify(now << 1 | 1 , mid + 1 , r , ql , qr);
		else modify(now << 1 , l , mid , ql , mid) , modify(now << 1 | 1 , mid + 1 , r , mid + 1 , qr);
		T[now] = T[now << 1] + T[now << 1 | 1];
	}
	inline void run(int rt) {
		fa[rt] = dep[rt] = siz = 0; dfs(rt);
		build(1 , 1 , N);
		for (int i = 1; i <= M; ++i) {
			int x = G[idx[i] - 1].fi , y = G[idx[i] - 1].se;
			if (fa[x] == y) swap(x , y);
			modify(1 , 1 , N , l[y] , r[y]);
			chkmax(ans[i] , T[1].val[0]);
		}
	}
} A , B;

inline void dfs(int x) {
	for (auto o : a[x]) {
		if (o.fi == fa[x]) continue; int y = o.fi;
		fa[y] = x , dep[y] = dep[x] + 1; dfs(y);
	}
	if (!rt || dep[x] > dep[rt]) rt = x;
}

int main() {

	scanf("%d" , &N);
	for (int i = 1; i < N; ++i) {
		int u , v , w;
		scanf("%d%d%d" , &u , &v , &w);
		a[u].emplace_back(mp(v , w));
		a[v].emplace_back(mp(u , w));
		G.emplace_back(mp(u , v));
	}
	scanf("%d" , &M);
	for (int i = 1; i <= M; ++i) scanf("%d" , &idx[i]);
	rt = 0 , fa[1] = dep[1] = 0; dfs(1);
	int r1 = rt , r2;
	rt = 0; fa[r1] = dep[r1] = 0; dfs(r1); r2 = rt;
	A.run(r1); B.run(r2);
	for (int i = 1; i <= M; ++i) printf("%d\n" , ans[i]);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair < int , int > pii;
#define fi first
#define se second
#define mp make_pair

const int MN = 5e5 + 5;

struct node { int val[2]; } T[MN << 2];
node operator + (node a , node b) {
	return (node) {max(a.val[0] , b.val[0]) , max(a.val[1] , b.val[1])};
}

int N , M , idx[MN] , ans[MN] , fa[MN] , dep[MN] , rt;
vector < pii > a[MN];
vector < pii > G;

inline void chkmax(int &x , int y) {
	x = max(x , y);
}

struct sol {
	int f[MN] , l[MN] , siz , r[MN] , rev[MN] , tg[MN << 2] , dep[MN] , fa[MN];
	inline void dfs(int x) {
		rev[l[x] = ++siz] = x;
		for (auto o : a[x]) {
			if (o.fi == fa[x]) continue; int y = o.fi;
			fa[y] = x , dep[y] = dep[x] + 1; f[y] = (f[x] + o.se) & 1;
			dfs(y);
		}
		r[x] = siz;
	}
	inline void build(int idx , int l , int r) {
		if (l == r) {
			T[idx].val[f[rev[l]]] = dep[rev[l]];
			return;
		}
		int mid = l + r >> 1;
		build(idx << 1 , l , mid) , build(idx << 1 | 1 , mid + 1 , r);
		T[idx] = T[idx << 1] + T[idx << 1 | 1];
	}
	inline void R(int o) {
		swap(T[o].val[0] , T[o].val[1]); tg[o] ^= 1;
	}
	inline void pushdown(int o) {
		if (tg[o]) R(o << 1) , R(o << 1 | 1) , rev[o] = 0;
	}
	inline void modify(int now , int l , int r , int ql , int qr) {
		if (l == ql && r == qr) return R(now);
		int mid = l + r >> 1; pushdown(now);
		if (mid >= qr) modify(now << 1 , l , mid , ql , qr);
		else if (mid + 1 <= ql) modify(now << 1 | 1 , mid + 1 , r , ql , qr);
		else modify(now << 1 , l , mid , ql , mid) , modify(now << 1 | 1 , mid + 1 , r , mid + 1 , qr);
		T[now] = T[now << 1] + T[now << 1 | 1];
	}
	inline void run(int rt) {
		fa[rt] = dep[rt] = siz = 0; dfs(rt);
		build(1 , 1 , N);
		for (int i = 1; i <= M; ++i) {
			int x = G[idx[i] - 1].fi , y = G[idx[i] - 1].se;
			if (fa[x] == y) swap(x , y);
			modify(1 , 1 , N , l[y] , r[y]);
			chkmax(ans[i] , T[1].val[0]);
		}
	}
} A , B;

inline void dfs(int x) {
	for (auto o : a[x]) {
		if (o.fi == fa[x]) continue; int y = o.fi;
		fa[y] = x , dep[y] = dep[x] + 1; dfs(y);
		if (!rt || dep[x] > dep[rt]) rt = x;
	}
}

int main() {

	scanf("%d" , &N);
	for (int i = 1; i < N; ++i) {
		int u , v , w;
		scanf("%d%d%d" , &u , &v , &w);
		a[u].emplace_back(mp(v , w));
		a[v].emplace_back(mp(u , v));
		G.emplace_back(mp(u , v));
	}
	scanf("%d" , &M);
	for (int i = 1; i <= M; ++i) scanf("%d" , &idx[i]);
	rt = 0 , fa[1] = dep[1] = 0; dfs(1);
	int r1 = rt , r2;
	rt = 0; fa[r1] = dep[r1] = 0; dfs(r1); r2 = rt;
	A.run(r1); B.run(r2);
	for (int i = 1; i <= M; ++i) printf("%d\n" , 1 + ans[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N = 500005;
int n,ex[N],ey[N],ez[N]; vector<int>G[N];
int Timest,st[N<<1][20],Log[N<<1],idst[N];
int Timedfn,dfn[N],node[N],tl[N],tr[N],dpt[N],fa[N];
inline int Mn(int x,int y){ return dpt[x] < dpt[y] ? x : y; }
inline int LCA(int x,int y){
	static int t; x = idst[x],y = idst[y]; if (x > y) swap(x,y); t = Log[y-x+1];
	return Mn(st[x][t],st[y-(1<<t)+1][t]);
}
int val[N];
inline void dfs(int x){
	dpt[x] = dpt[fa[x]] + 1;
	tl[x] = dfn[x] = ++Timedfn; st[idst[x] = ++Timest][0] = x; node[Timedfn] = x;
	for (int y,e,i = 0; i < G[x].size(); ++i){
		e = G[x][i];
		if ((y=ex[e]+ey[e]-x)^fa[x]){
			fa[y] = x;
			val[y] = val[x] ^ ez[e];
			dfs(y);
			st[++Timest][0] = x;
		}
	}
	tr[x] = Timedfn;
}
inline int Dist(int x,int y){ if (!x || !y) return 0; return dpt[x] + dpt[y] - (dpt[LCA(x,y)]<<1); }
struct data{ int x,y; int get(){ return Dist(x,y); } };
data operator + (data A,data B){
	static int tmp[5],lt,i,j,ansl; static data Ans;
	lt = 0,Ans = A,ansl = Dist(A.x,A.y);
	if (A.x) tmp[++lt] = A.x; if (A.y) tmp[++lt] = A.y;
	if (B.x) tmp[++lt] = B.x; if (B.y) tmp[++lt] = B.y;
	for (i = 1; i <= lt; ++i)
	for (j = i+1; j <= lt; ++j){
		if (Dist(tmp[i],tmp[j]) > ansl){
			ansl = Dist(tmp[i],tmp[j]);
			Ans.x = tmp[i],Ans.y = tmp[j];
		}
	}
	if (lt == 1) Ans.x = tmp[1],Ans.y = 0;
	return Ans;
}
data f0[N<<2],f1[N<<2]; bool rev[N<<2];
#define lc o<<1
#define rc o<<1|1
inline void up(int o){ f1[o] = f1[lc] + f1[rc],f0[o] = f0[lc] + f0[rc]; }
inline void Build(int o,int l,int r){
	if (l == r){ if (val[node[l]]) f1[o].x = node[l]; else f0[o].x = node[l]; return; }
	int mid = l+r>>1; Build(lc,l,mid),Build(rc,mid+1,r),up(o);
}
inline void Rev(int o){ rev[o] ^= 1,swap(f0[o],f1[o]); }
inline void down(int o){ if (rev[o]) rev[o] = 0,Rev(lc),Rev(rc); }
int ll,rr;
inline void Modify(int o,int l,int r){
	if (ll <= l && rr >= r){ Rev(o); return; }
	down(o); int mid = l+r>>1; if (ll <= mid) Modify(lc,l,mid); if (rr > mid) Modify(rc,mid+1,r); up(o);
}

int main(){
	int i,j;
	read(n);
	for (i = 1; i < n; ++i)
		read(ex[i]),read(ey[i]),read(ez[i]),G[ex[i]].push_back(i),G[ey[i]].push_back(i);
	dfs(1);
	for (i = 1; i <= Timest; ++i){
		Log[i] = Log[i-1];
		while ((1<<Log[i]+1) < i) ++Log[i];
	}
	for (j = 1; j <= Log[Timest]; ++j)
	for (i = 1; i+(1<<j)-1 <= Timest; ++i) st[i][j] = Mn(st[i][j-1],st[i+(1<<j-1)][j-1]);
	Build(1,1,n);
	for (i = 1; i < n; ++i) if (fa[ey[i]] == ex[i]) swap(ey[i],ex[i]);
	int q,z;
	read(q);
//	cout << ' ' << max(f1[1].get(),f0[1].get()) << '\n';
	while (q--){
		read(z),ll = tl[ex[z]],rr = tr[ex[z]],Modify(1,1,n);
		cout << max(f1[1].get(),f0[1].get()) << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}
template <typename T> void chkmin(T &x,T y){x>y?x=y:T();}
template <typename T> void readint(T &x)
{
	x=0;int f=1;char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	x*=f;
}
const int MOD=998244353;
inline int dmy(int x){return x>=MOD?x-MOD:x;}
inline void inc(int &x,int y){x=dmy(x+y);}
int qmi(int x,int y)
{
	int ans=1;
	for(;y;y>>=1,x=1ll*x*x%MOD)
		if(y&1)ans=1ll*ans*x%MOD;
	return ans;
}
const int MAXN=500005,MAXK=19;

int n,_u[MAXN],_v[MAXN];
vector<pii> G[MAXN];
int dfn[MAXN],size[MAXN],dep[MAXN],anc[MAXN][MAXK],col[MAXN],ded[MAXN],dfn_cnt,dd[MAXN];
void dfs(int u,int pa)
{
	size[u]=1;
	dfn[u]=++dfn_cnt;ded[dfn_cnt]=u;
	for(int i=1;i<MAXK;++i)anc[u][i]=anc[anc[u][i-1]][i-1];
	for(auto p:G[u])
	{
		int v=p.x,c=p.y;
		if(v==pa)continue;
		dep[v]=dep[u]+1;
		anc[v][0]=u;
		col[v]=col[u]^c;
		dfs(v,u);
		size[u]+=size[v];
	}
}
void getdep(int u,int pa)
{
	for(auto p:G[u])
	{
		int v=p.x;
		if(v==pa)continue;
		dd[v]=dd[u]+1;
		getdep(v,u);
	}
}
int lca(int u,int v)
{
	if(dep[u]>dep[v])swap(u,v);
	for(int i=MAXK-1;i>=0;--i)if(dep[v]-dep[u]>=(1<<i))v=anc[v][i];
	if(u==v)return u;
	for(int i=MAXK-1;i>=0;--i)if(anc[u][i]!=anc[v][i])u=anc[u][i],v=anc[v][i];
	return anc[u][0];
}
int dist(int u,int v){return u?dep[u]+dep[v]-2*dep[lca(u,v)]:0;}
int mu[MAXN<<2][2],tag[MAXN<<2];
void update(int id)
{
	for(int t=0;t<=1;++t)
		mu[id][t]=(dep[mu[id<<1][t]]>dep[mu[id<<1|1][t]]?mu[id<<1][t]:mu[id<<1|1][t]);
}
void pushdown(int id)
{
	if(!tag[id])return;
	swap(mu[id<<1][0],mu[id<<1][1]);tag[id<<1]^=1;
	swap(mu[id<<1|1][0],mu[id<<1|1][1]);tag[id<<1|1]^=1;
	tag[id]=0;
}
void build(int id,int l,int r)
{
	if(l==r){mu[id][col[ded[l]]]=ded[l];return;}
	int mid=(l+r)>>1;
	build(id<<1,l,mid);
	build(id<<1|1,mid+1,r);
	update(id);
}
void modify(int id,int l,int r,int ql,int qr)
{
	if(l==ql && r==qr){swap(mu[id][0],mu[id][1]);tag[id]^=1;return;}
	pushdown(id);
	int mid=(l+r)>>1;
	if(qr<=mid)modify(id<<1,l,mid,ql,qr);
	else if(ql>mid)modify(id<<1|1,mid+1,r,ql,qr);
	else modify(id<<1,l,mid,ql,mid),modify(id<<1|1,mid+1,r,mid+1,qr);
	update(id);
}
int query(int id,int l,int r,int ql,int qr,int t)
{
	if(l==ql && r==qr)return mu[id][t];
	pushdown(id);
	int mid=(l+r)>>1;
	if(qr<=mid)return query(id<<1,l,mid,ql,qr,t);
	if(ql>mid)return query(id<<1|1,mid+1,r,ql,qr,t);
	int u=query(id<<1,l,mid,ql,mid,t),v=query(id<<1|1,mid+1,r,mid+1,qr,t);
	return dep[u]>dep[v]?u:v;
}

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	int Q;
	readint(n);
	for(int i=1;i<n;++i)
	{
		int c;
		readint(_u[i]),readint(_v[i]),readint(c);
		G[_u[i]].pb(mp(_v[i],c));G[_v[i]].pb(mp(_u[i],c));
	}
	dep[0]=-1;dep[1]=0;dfs(1,-1);
	for(int i=1;i<n;++i)if(dep[_u[i]]>dep[_v[i]])swap(_u[i],_v[i]);
	pii p[2];
	for(int t=0;t<=1;++t)
	{
		p[t].x=0;
		for(int j=1;j<=n;++j)if(col[j]==t){p[t].x=j;break;}
		if(!p[t].x)continue;
		dd[p[t].x]=0;getdep(p[t].x,-1);
		p[t].y=p[t].x;
		for(int j=1;j<=n;++j)if(col[j]==t && dd[j]>dd[p[t].y])p[t].y=j;
		dd[p[t].y]=0;getdep(p[t].y,-1);
		for(int j=1;j<=n;++j)if(col[j]==t && dd[j]>dd[p[t].x])p[t].x=j;
	}
	build(1,1,n);
	readint(Q);
	while(Q--)
	{
		int x;
		readint(x);
		x=_v[x];
		modify(1,1,n,dfn[x],dfn[x]+size[x]-1);
		pii q[2];
		for(int t=0;t<=1;++t)
		{
			vector<int> g;
			if(dfn[p[t].x]<dfn[x] || dfn[p[t].x]>=dfn[x]+size[x])g.pb(p[t].x);
			if(dfn[p[t^1].x]>=dfn[x] && dfn[p[t^1].x]<dfn[x]+size[x])g.pb(p[t^1].x);
			if(dfn[p[t].y]<dfn[x] || dfn[p[t].y]>=dfn[x]+size[x])g.pb(p[t].y);
			if(dfn[p[t^1].y]>=dfn[x] && dfn[p[t^1].y]<dfn[x]+size[x])g.pb(p[t^1].y);
			int w=query(1,1,n,dfn[x],dfn[x]+size[x]-1,t);
			if(w)g.pb(w);
			q[t]=mp(0,0);
			for(int i=0;i<g.size();++i)
				for(int j=i;j<g.size();++j)
				{
					int u=g[i],v=g[j];
					if(u && v && dist(u,v)>=dist(q[t].x,q[t].y))q[t]=mp(u,v);
				}
		}
		p[0]=q[0],p[1]=q[1];
		printf("%d\n",max(dist(p[0].x,p[0].y),dist(p[1].x,p[1].y)));
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}
template <typename T> void chkmin(T &x,T y){x>y?x=y:T();}
template <typename T> void readint(T &x)
{
	x=0;int f=1;char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	x*=f;
}
const int MOD=998244353;
inline int dmy(int x){return x>=MOD?x-MOD:x;}
inline void inc(int &x,int y){x=dmy(x+y);}
int qmi(int x,int y)
{
	int ans=1;
	for(;y;y>>=1,x=1ll*x*x%MOD)
		if(y&1)ans=1ll*ans*x%MOD;
	return ans;
}
const int MAXN=500005,MAXK=19;

int n,_u[MAXN],_v[MAXN];
vector<pii> G[MAXN];
int dfn[MAXN],size[MAXN],dep[MAXN],anc[MAXN][MAXK],col[MAXN],ded[MAXN],dfn_cnt;
void dfs(int u,int pa)
{
	size[u]=1;
	dfn[u]=++dfn_cnt;ded[dfn_cnt]=u;
	for(int i=1;i<MAXK;++i)anc[u][i]=anc[anc[u][i-1]][i-1];
	for(auto p:G[u])
	{
		int v=p.x,c=p.y;
		if(v==pa)continue;
		dep[v]=dep[u]+1;
		anc[v][0]=u;
		col[v]=col[u]^c;
		dfs(v,u);
		size[u]+=size[v];
	}
}
void getdep(int u,int pa)
{
	for(auto p:G[u])
	{
		int v=p.x;
		if(v==pa)continue;
		dep[v]=dep[u]+1;
		getdep(v,u);
	}
}
int lca(int u,int v)
{
	if(dep[u]>dep[v])swap(u,v);
	for(int i=MAXK-1;i>=0;--i)if(dep[v]-dep[u]>=(1<<i))v=anc[v][i];
	if(u==v)return u;
	for(int i=MAXK-1;i>=0;--i)if(anc[u][i]!=anc[v][i])u=anc[u][i],v=anc[v][i];
	return anc[u][0];
}
int dist(int u,int v){return u?dep[u]+dep[v]-2*dep[lca(u,v)]:0;}
int mu[MAXN<<2][2],tag[MAXN<<2];
void update(int id)
{
	for(int t=0;t<=1;++t)
		mu[id][t]=(dep[mu[id<<1][t]]>dep[mu[id<<1|1][t]]?mu[id<<1][t]:mu[id<<1|1][t]);
}
void pushdown(int id)
{
	if(!tag[id])return;
	swap(mu[id<<1][0],mu[id<<1][1]);tag[id<<1]^=1;
	swap(mu[id<<1|1][0],mu[id<<1|1][1]);tag[id<<1|1]^=1;
	tag[id]=0;
}
void build(int id,int l,int r)
{
	if(l==r){mu[id][col[ded[l]]]=ded[l];return;}
	int mid=(l+r)>>1;
	build(id<<1,l,mid);
	build(id<<1|1,mid+1,r);
	update(id);
}
void modify(int id,int l,int r,int ql,int qr)
{
	if(l==ql && r==qr){swap(mu[id][0],mu[id][1]);tag[id]^=1;return;}
	pushdown(id);
	int mid=(l+r)>>1;
	if(qr<=mid)modify(id<<1,l,mid,ql,qr);
	else if(ql>mid)modify(id<<1|1,mid+1,r,ql,qr);
	else modify(id<<1,l,mid,ql,mid),modify(id<<1|1,mid+1,r,mid+1,qr);
	update(id);
}
int query(int id,int l,int r,int ql,int qr,int t)
{
	if(l==ql && r==qr)return mu[id][t];
	pushdown(id);
	int mid=(l+r)>>1;
	if(qr<=mid)return query(id<<1,l,mid,ql,qr,t);
	if(ql>mid)return query(id<<1|1,mid+1,r,ql,qr,t);
	int u=query(id<<1,l,mid,ql,mid,t),v=query(id<<1|1,mid+1,r,mid+1,qr,t);
	return dep[u]>dep[v]?u:v;
}

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	int Q;
	readint(n);
	for(int i=1;i<n;++i)
	{
		int c;
		readint(_u[i]),readint(_v[i]),readint(c);
		G[_u[i]].pb(mp(_v[i],c));G[_v[i]].pb(mp(_u[i],c));
	}
	pii p[2];
	for(int t=0;t<=1;++t)
	{
		p[t].x=0;
		for(int j=1;j<=n;++j)if(col[j]==t){p[t].x=j;break;}
		if(!p[t].x)continue;
		dep[p[t].x]=0;getdep(p[t].x,-1);
		p[t].y=p[t].x;
		for(int j=1;j<=n;++j)if(col[j]==t && dep[j]>dep[p[t].y])p[t].y=j;
		dep[p[t].y]=0;getdep(p[t].y,-1);
		for(int j=1;j<=n;++j)if(col[j]==t && dep[j]>dep[p[t].x])p[t].x=j;
	}
	dep[0]=-1;dep[1]=0;dfs(1,-1);
	for(int i=1;i<n;++i)if(dep[_u[i]]>dep[_v[i]])swap(_u[i],_v[i]);
	build(1,1,n);
	readint(Q);
	while(Q--)
	{
		int x;
		readint(x);
		x=_v[x];
		modify(1,1,n,dfn[x],dfn[x]+size[x]-1);
		pii q[2];
		for(int t=0;t<=1;++t)
		{
			vector<int> g;
			if(dfn[p[t].x]<dfn[x] || dfn[p[t].x]>=dfn[x]+size[x])g.pb(p[t].x);
			if(dfn[p[t^1].x]>=dfn[x] && dfn[p[t^1].x]<dfn[x]+size[x])g.pb(p[t^1].x);
			if(dfn[p[t].y]<dfn[x] || dfn[p[t].y]>=dfn[x]+size[x])g.pb(p[t].y);
			if(dfn[p[t^1].y]>=dfn[x] && dfn[p[t^1].y]<dfn[x]+size[x])g.pb(p[t^1].y);
			int w=query(1,1,n,dfn[x],dfn[x]+size[x]-1,t);
			if(w)g.pb(w);
			q[t]=mp(0,0);
			for(int i=0;i<g.size();++i)
				for(int j=i;j<g.size();++j)
				{
					int u=g[i],v=g[j];
					if(u && v && dist(u,v)>=dist(q[t].x,q[t].y))q[t]=mp(u,v);
				}
		}
		p[0]=q[0],p[1]=q[1];
		printf("%d\n",max(dist(p[0].x,p[0].y),dist(p[1].x,p[1].y)));
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}
template <typename T> void chkmin(T &x,T y){x>y?x=y:T();}
template <typename T> void readint(T &x)
{
	x=0;int f=1;char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	x*=f;
}
const int MOD=998244353;
inline int dmy(int x){return x>=MOD?x-MOD:x;}
inline void inc(int &x,int y){x=dmy(x+y);}
int qmi(int x,int y)
{
	int ans=1;
	for(;y;y>>=1,x=1ll*x*x%MOD)
		if(y&1)ans=1ll*ans*x%MOD;
	return ans;
}
const int MAXN=500005,MAXK=19;

int n,_u[MAXN],_v[MAXN];
vector<pii> G[MAXN];
int dfn[MAXN],size[MAXN],d0[MAXN],d1[MAXN],col[MAXN],ded[MAXN],dfn_cnt;
void dfs(int u,int pa,int *dep)
{
	size[u]=1;
	dfn[u]=++dfn_cnt;ded[dfn_cnt]=u;
	for(auto p:G[u])
	{
		int v=p.x,c=p.y;
		if(v==pa)continue;
		dep[v]=dep[u]+1;
		col[v]=col[u]^c;
		dfs(v,u,dep);
		size[u]+=size[v];
	}
}
int co[MAXN<<2],mu[MAXN<<2][2][2],tag[MAXN<<2];
void maintain(int id)
{
	swap(mu[id][0][0],mu[id][1][0]);
	swap(mu[id][0][1],mu[id][1][1]);
	co[id]^=1;tag[id]^=1;
}
void update(int id)
{
	for(int t=0;t<=1;++t)
		mu[id][0][t]=max(mu[id<<1][0][t],mu[id<<1|1][0][t]),
		mu[id][1][t]=max(mu[id<<1][1][t],mu[id<<1|1][1][t]);
}
void pushdown(int id)
{
	if(!tag[id])return;
	maintain(id<<1),maintain(id<<1|1);
	tag[id]=0;
}
void build(int id,int l,int r)
{
	tag[id]=0;
	if(l==r)
	{
		co[id]=col[ded[l]];
		mu[id][co[id]][0]=d0[ded[l]];
		mu[id][co[id]][1]=d1[ded[l]];
		return;
	}
	int mid=(l+r)>>1;
	build(id<<1,l,mid);
	build(id<<1|1,mid+1,r);
	update(id);
}
void modify(int id,int l,int r,int ql,int qr)
{
	if(l==ql && r==qr)
	{
		maintain(id);
		return;
	}
	pushdown(id);
	int mid=(l+r)>>1;
	if(qr<=mid)modify(id<<1,l,mid,ql,qr);
	else if(ql>mid)modify(id<<1|1,mid+1,r,ql,qr);
	else modify(id<<1,l,mid,ql,mid),modify(id<<1|1,mid+1,r,mid+1,qr);
	update(id);
}
int query(int id,int l,int r,int ql,int qr,int t,int s)
{
	if(l==ql && r==qr)return mu[id][t][s];
	pushdown(id);
	int mid=(l+r)>>1;
	if(qr<=mid)return query(id<<1,l,mid,ql,qr,t,s);
	if(ql>mid)return query(id<<1|1,mid+1,r,ql,qr,t,s);
	return max(query(id<<1,l,mid,ql,mid,t,s),query(id<<1|1,mid+1,r,mid+1,qr,t,s));
}
int qcol(int id,int l,int r,int x)
{
	if(l==r)return co[id];
	pushdown(id);
	int mid=(l+r)>>1;
	if(x<=mid)return qcol(id<<1,l,mid,x);
	return qcol(id<<1|1,mid+1,r,x);
}

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	int Q;
	readint(n);
	for(int i=1;i<n;++i)
	{
		int c;
		readint(_u[i]),readint(_v[i]),readint(c);
		G[_u[i]].pb(mp(_v[i],c));G[_v[i]].pb(mp(_u[i],c));
	}
	dfs(1,-1,d1);
	int u=1;
	for(int i=2;i<=n;++i)if(d1[i]>d1[u])u=i;
	dfn_cnt=0;dfs(u,-1,d0);
	int v=1;
	for(int i=2;i<=n;++i)if(d0[i]>d0[v])v=i;
	d1[v]=0;dfn_cnt=0;dfs(v,-1,d1);
	d1[0]=d0[0]=-1;
	for(int i=1;i<n;++i)
		if(d1[_u[i]]>d1[_v[i]])swap(_u[i],_v[i]);
	memset(mu,-1,sizeof(mu));
	build(1,1,n);
	readint(Q);
	while(Q--)
	{
		int x;
		readint(x);
		x=_v[x];
		modify(1,1,n,dfn[x],dfn[x]+size[x]-1);
		int cu=qcol(1,1,n,dfn[u]),cv=qcol(1,1,n,dfn[v]);
		if(cu==cv)printf("%d\n",d0[v]);
		else printf("%d\n",max(mu[1][cu][0],mu[1][cv][1]));
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}
template <typename T> void chkmin(T &x,T y){x>y?x=y:T();}
template <typename T> void readint(T &x)
{
	x=0;int f=1;char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	x*=f;
}
const int MOD=998244353;
inline int dmy(int x){return x>=MOD?x-MOD:x;}
inline void inc(int &x,int y){x=dmy(x+y);}
int qmi(int x,int y)
{
	int ans=1;
	for(;y;y>>=1,x=1ll*x*x%MOD)
		if(y&1)ans=1ll*ans*x%MOD;
	return ans;
}
const int MAXN=500005,MAXK=19;

int n,_u[MAXN],_v[MAXN];
vector<pii> G[MAXN];
int dfn[MAXN],size[MAXN],d0[MAXN],d1[MAXN],col[MAXN],ded[MAXN],dfn_cnt;
void dfs(int u,int pa,int *dep)
{
	size[u]=1;
	dfn[u]=++dfn_cnt;ded[dfn_cnt]=u;
	for(auto p:G[u])
	{
		int v=p.x,c=p.y;
		if(v==pa)continue;
		dep[v]=dep[u]+1;
		col[v]=col[u]^c;
		dfs(v,u,dep);
		size[u]+=size[v];
	}
}
int co[MAXN<<2],mu[MAXN<<2][2][2],tag[MAXN<<2];
void maintain(int id)
{
	swap(mu[id][0][0],mu[id][1][0]);
	swap(mu[id][0][1],mu[id][1][1]);
	co[id]^=1;tag[id]^=1;
}
void update(int id)
{
	for(int t=0;t<=1;++t)
		mu[id][0][t]=max(mu[id<<1][0][t],mu[id<<1|1][0][t]),
		mu[id][1][t]=max(mu[id<<1][1][t],mu[id<<1|1][1][t]);
}
void pushdown(int id)
{
	if(!tag[id])return;
	maintain(id<<1),maintain(id<<1|1);
	tag[id]=0;
}
void build(int id,int l,int r)
{
	if(l==r)
	{
		co[l]=col[ded[l]];
		mu[id][co[l]][0]=d0[ded[l]];
		mu[id][co[l]][1]=d1[ded[l]];
		return;
	}
	int mid=(l+r)>>1;
	build(id<<1,l,mid);
	build(id<<1|1,mid+1,r);
	update(id);
}
void modify(int id,int l,int r,int ql,int qr)
{
	if(l==ql && r==qr)
	{
		maintain(id);
		return;
	}
	pushdown(id);
	int mid=(l+r)>>1;
	if(qr<=mid)modify(id<<1,l,mid,ql,qr);
	else if(ql>mid)modify(id<<1|1,mid+1,r,ql,qr);
	else modify(id<<1,l,mid,ql,mid),modify(id<<1|1,mid+1,r,mid+1,qr);
	update(id);
}
int query(int id,int l,int r,int ql,int qr,int t,int s)
{
	if(l==ql && r==qr)return mu[id][t][s];
	pushdown(id);
	int mid=(l+r)>>1;
	if(qr<=mid)return query(id<<1,l,mid,ql,qr,t,s);
	if(ql>mid)return query(id<<1|1,mid+1,r,ql,qr,t,s);
	return max(query(id<<1,l,mid,ql,mid,t,s),query(id<<1|1,mid+1,r,mid+1,qr,t,s));
}
int qcol(int id,int l,int r,int x)
{
	if(l==r)return co[id];
	pushdown(id);
	int mid=(l+r)>>1;
	if(x<=mid)return qcol(id<<1,l,mid,x);
	return qcol(id<<1|1,mid+1,r,x);
}

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	int Q;
	readint(n);
	for(int i=1;i<n;++i)
	{
		int c;
		readint(_u[i]),readint(_v[i]),readint(c);
		G[_u[i]].pb(mp(_v[i],c));G[_v[i]].pb(mp(_u[i],c));
	}
	dfs(1,-1,d1);
	int u=1;
	for(int i=2;i<=n;++i)if(d1[i]>d1[u])u=i;
	dfn_cnt=0;dfs(u,-1,d0);
	int v=1;
	for(int i=2;i<=n;++i)if(d0[i]>d0[v])v=i;
	d1[v]=0;dfn_cnt=0;dfs(v,-1,d1);
	d1[0]=-1;
	for(int i=1;i<n;++i)
		if(d1[_u[i]]>d1[_v[i]])swap(_u[i],_v[i]);
	build(1,1,n);
	readint(Q);
	while(Q--)
	{
		int x;
		readint(x);
		x=_v[x];
		modify(1,1,n,dfn[x],dfn[x]+size[x]-1);
		int cu=qcol(1,1,n,dfn[u]),cv=qcol(1,1,n,dfn[v]);
		if(cu==cv)printf("%d\n",d0[v]);
		else printf("%d\n",max(query(1,1,n,dfn[u],dfn[u]+size[u]-1,cu,1),
			query(1,1,n,dfn[v],dfn[v]+size[v]-1,cv,0)));
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}
template <typename T> void chkmin(T &x,T y){x>y?x=y:T();}
template <typename T> void readint(T &x)
{
	x=0;int f=1;char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	x*=f;
}
const int MOD=998244353;
inline int dmy(int x){return x>=MOD?x-MOD:x;}
inline void inc(int &x,int y){x=dmy(x+y);}
int qmi(int x,int y)
{
	int ans=1;
	for(;y;y>>=1,x=1ll*x*x%MOD)
		if(y&1)ans=1ll*ans*x%MOD;
	return ans;
}
const int MAXN=500005,MAXK=19;

int n,_u[MAXN],_v[MAXN];
vector<pii> G[MAXN];
int dfn[MAXN],size[MAXN],d0[MAXN],d1[MAXN],col[MAXN],ded[MAXN],dfn_cnt;
void dfs(int u,int pa,int *dep)
{
	size[u]=1;
	dfn[u]=++dfn_cnt;ded[dfn_cnt]=u;
	for(auto p:G[u])
	{
		int v=p.x,c=p.y;
		if(v==pa)continue;
		dep[v]=dep[u]+1;
		col[v]=col[u]^c;
		dfs(v,u,dep);
		size[u]+=size[v];
	}
}
int co[MAXN<<2],mu[MAXN<<2][2][2],tag[MAXN<<2];
void maintain(int id)
{
	swap(mu[id][0][0],mu[id][0][1]);
	swap(mu[id][1][0],mu[id][1][1]);
	co[id]^=1;tag[id]^=1;
}
void update(int id)
{
	for(int t=0;t<=1;++t)
		mu[id][0][t]=max(mu[id<<1][0][t],mu[id<<1|1][0][t]),
		mu[id][1][t]=max(mu[id<<1][1][t],mu[id<<1|1][1][t]);
}
void pushdown(int id)
{
	if(!tag[id])return;
	maintain(id<<1),maintain(id<<1|1);
	tag[id]=0;
}
void build(int id,int l,int r)
{
	if(l==r)
	{
		co[l]=col[ded[l]];
		mu[id][co[l]][0]=d0[ded[l]];
		mu[id][co[l]^1][0]=d1[ded[l]];
		return;
	}
	int mid=(l+r)>>1;
	build(id<<1,l,mid);
	build(id<<1|1,mid+1,r);
	update(id);
}
void modify(int id,int l,int r,int ql,int qr)
{
	if(l==ql && r==qr)
	{
		maintain(id);
		return;
	}
	pushdown(id);
	int mid=(l+r)>>1;
	if(qr<=mid)modify(id<<1,l,mid,ql,qr);
	else if(ql>mid)modify(id<<1|1,mid+1,r,ql,qr);
	else modify(id<<1,l,mid,ql,mid),modify(id<<1|1,mid+1,r,mid+1,qr);
	update(id);
}
int query(int id,int l,int r,int ql,int qr,int t,int s)
{
	if(l==ql && r==qr)return mu[id][t][s];
	pushdown(id);
	int mid=(l+r)>>1;
	if(qr<=mid)return query(id<<1,l,mid,ql,qr,t,s);
	if(ql>mid)return query(id<<1|1,mid+1,r,ql,qr,t,s);
	int u=query(id<<1,l,mid,ql,mid,t,s),v=query(id<<1|1,mid+1,r,mid+1,qr,t,s);
	return max(u,v);
}
int qcol(int id,int l,int r,int x)
{
	if(l==r)return co[id];
	pushdown(id);
	int mid=(l+r)>>1;
	if(x<=mid)return qcol(id<<1,l,mid,x);
	return qcol(id<<1|1,mid+1,r,x);
}

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	int Q;
	readint(n);
	for(int i=1;i<n;++i)
	{
		int c;
		readint(_u[i]),readint(_v[i]),readint(c);
		G[_u[i]].pb(mp(_v[i],c));G[_v[i]].pb(mp(_u[i],c));
	}
	dfs(1,-1,d1);
	int u=1;
	for(int i=2;i<=n;++i)if(d1[i]>d1[u])u=i;
	dfn_cnt=0;dfs(u,-1,d0);
	int v=1;
	for(int i=2;i<=n;++i)if(d0[i]>d0[v])v=i;
	d1[v]=0;dfn_cnt=0;dfs(v,-1,d1);
	d1[0]=-1;
	for(int i=1;i<n;++i)
		if(d1[_u[i]]>d1[_v[i]])swap(_u[i],_v[i]);
	build(1,1,n);
	readint(Q);
	while(Q--)
	{
		int x;
		readint(x);
		x=_v[x];
		modify(1,1,n,dfn[x],dfn[x]+size[x]-1);
		int cu=qcol(1,1,n,dfn[u]),cv=qcol(1,1,n,dfn[v]);
		if(cu==cv)printf("%d\n",d0[v]);
		else printf("%d\n",max(query(1,1,n,dfn[u],dfn[u]+size[u]-1,cu,0),
			query(1,1,n,dfn[v],dfn[v]+size[v]-1,cv,1)));
	}
	return 0;
}