#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1

using LL = long long;
using ULL = unsigned long long;
using pii = pair<int,int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);
char nc(){
	static char buf[1000000], *p = buf, *q = buf;
	return p == q && (q = (p = buf) + fread(buf, 1, 1000000, stdin), p == q)
			   ? EOF
			   : *p++;
}
int rd(){
	int res = 0;
	char c = nc();
	while (!isdigit(c))
		c = nc();
	while (isdigit(c))
		res = res * 10 + c - '0', c = nc();
	return res;
}

const int N = 5e5 + 10;

int n, Q, dfs_cnt;
bool edge[N];
vector<pii> V[N];
int buf[N];
bool tag[N];

struct Tree{
	int lft[N], rgt[N],bottom[N], l[N<<2], r[N<<2], S[N<<2][2];
	bool lazy[N<<2];
	void dfs(int x, int fa, int dep, bool f){
		lft[x] = ++dfs_cnt;
		buf[dfs_cnt] = dep;
		tag[dfs_cnt] = f;
		for(auto p : V[x]){
			if(p.fi == fa)	continue;
			bottom[p.se] = p.fi;
			dfs(p.fi, x, dep + 1, f ^ edge[p.se]);
		}
		rgt[x] = dfs_cnt;
	}
	void build(int o, int ll, int rr){
		l[o] = ll;
		r[o] = rr;
		lazy[o] = 0;
		if(ll < rr){
			int mid = gmid;
			build(lson, ll, mid);
			build(rson, mid + 1, rr);
			S[o][0] = max(S[lson][0], S[rson][0]);
			S[o][1] = max(S[lson][1], S[rson][1]);
		} else {
			if(tag[ll]){
				S[o][0] = 0;
				S[o][1] = buf[ll];
			} else {
				S[o][0] = buf[ll];
				S[o][1] = 0;
			}
		}
	}
	int pushdown(int o){
		int mid = gmid;
		if(lazy[o]){
			update(lson, l[o], mid);
			update(rson, mid+1, r[o]);
			lazy[o] = 0;
		}
		return mid;
	}
	void update(int o, int ll, int rr){
		if(l[o] == ll && r[o] == rr){
			lazy[o] ^= 1;
			swap(S[o][0], S[o][1]);
			return;
		}
		int mid = pushdown(o);
		if(rr <= mid)	update(lson, ll, rr);
		else if(ll > mid)	update(rson, ll, rr);
		else{
			update(lson, ll, mid);
			update(rson, mid+1, rr);
		}
		S[o][0] = max(S[lson][0], S[rson][0]);
		S[o][1] = max(S[lson][1], S[rson][1]);
	}
	void init(int x){
		dfs_cnt = 0;
		dfs(x, -1, 0, 0);
		build(1, 1, n);
	}
	void flip(int x){
		x = bottom[x];
		update(1, lft[x], rgt[x]);
	}
}tree[2];

int dist[N];
int bfs(int x){
	rep(i, 1, n+1)	dist[i] = inf;
	dist[x] = 0;
	int ret = x;
	queue<int> Q;
	Q.emplace(x);
	while(!Q.empty()){
		x = Q.front(); Q.pop();
		if(dist[x] > dist[ret])	ret = x;
		for(pii p : V[x]){
			if(dist[p.fi] == inf){
				dist[p.fi] = dist[x] + 1;
				Q.emplace(p.fi);
			}
		}
	}
	return ret;
}

int main(){
	int x, y, z;
	n = rd();
	rep(i, 1, n){
		x = rd();
		y = rd();
		z = rd();
		V[x].pb(y, i);
		V[y].pb(x, i);
		edge[i] = z;
	}
	x = bfs(1);
	y = bfs(x);
	tree[0].init(x);
	tree[1].init(y);
	Q = rd();
	while(Q--){
		x = rd();
		tree[0].flip(x);
		tree[1].flip(x);
		printf("%d\n", max(tree[0].S[1][0], tree[1].S[1][0]));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define gmid l[o]+r[o]>>1

using LL = long long;
using ULL = unsigned long long;
using pii = pair<int,int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 5e5 + 10;
const int L = 1e7 + 10;
const int M = 2e7 + 10;

int n, Q;
vector<pii> V[N];
bool edge[N];
bool mk[N];
int dfs_cnt, tree_id, node_num, tree[L], root[L];
vector<int> belong[N];
multiset<int> ST[N][2], ans;
int sz[N], val[N];
int S[M][2], l[M], r[M], lson[M], rson[M];
bool lazy[M];
int cur[N][2];
vector<pii> info[N];

void dfs(int x, int fa){
	sz[x] = 1;
	for(auto p : V[x]){
		if(p.fi == fa || mk[p.fi])	continue;
		dfs(p.fi, x);
		sz[x] += sz[p.fi];
	}
}

pii dfs(int x, int fa, int sum){
	pii ret = mp(inf, 0);
	int mx = sum - sz[x];
	for(auto p : V[x]){
		if(p.fi == fa || mk[p.fi])	continue;
		ret = min(ret, dfs(p.fi, x, sum));
		mx = max(mx, sz[p.fi]);
	}
	return min(ret, mp(mx, x));
}

void getpath(int tree_id, int idx, int x, int fa, int dep, bool f){
	int lft = ++dfs_cnt;

	cur[dfs_cnt][0] = dep;
	cur[dfs_cnt][1] = f;

	for(auto p : V[x]){
		if(p.fi == fa || mk[p.fi])	continue;
		getpath(tree_id, p.se, p.fi, x, dep + 1, f ^ edge[p.se]);
	}

	int rgt = dfs_cnt;

	belong[idx].pb(tree_id);
	info[idx].pb(lft, rgt);
}

void maintain(int o){
	S[o][0] = max(S[lson[o]][0], S[rson[o]][0]);
	S[o][1] = max(S[lson[o]][1], S[rson[o]][1]);
}

int build(int ll, int rr){
	int o = ++node_num;
	l[o] = ll;
	r[o] = rr;
	lazy[o] = 0;
	if(ll < rr){
		int mid = gmid;
		lson[o] = build(ll, mid);
		rson[o] = build(mid+1, rr);
		maintain(o);
	} else {
		if(cur[ll][1]){
			S[o][0] = 0;
			S[o][1] = cur[ll][0];
		} else {
			S[o][0] = cur[ll][0];
			S[o][1] = 0;
		}
	}
	return o;
}

void recal(int x){
	val[x] = 0;

	if(ST[x][0].size() > 1){
		auto it = ST[x][0].rbegin();
		it--;
		val[x] = max(val[x], *it + *ST[x][0].rbegin());
	}

	if(ST[x][1].size() > 1){
		auto it = ST[x][1].rbegin();
		it--;
		val[x] = max(val[x], *it + *ST[x][1].rbegin());
	}
}

void doit(int x){
	dfs(x, -1);
	x = dfs(x, -1, sz[x]).se;

	mk[x] = 1;

	for(auto p : V[x]){
		if(!mk[p.fi]){
			doit(p.fi);
		}
	}
	int r;

	for(auto p : V[x]){
		if(mk[p.fi])	continue;

		++tree_id;
		root[tree_id] = x;

		dfs_cnt = 0;

		getpath(tree_id, p.se, p.fi, x, 1, edge[p.se]);

		r = tree[tree_id] = build(1, dfs_cnt);

		ST[x][0].insert(S[r][0]);
		ST[x][1].insert(S[r][1]);
	}

	recal(x);

	ans.insert(val[x]);

	mk[x] = 0;
}

void update(int o, int ll, int rr);

int pushdown(int o){
	int mid = gmid;
	if(lazy[o]){
		update(lson[o], l[o], mid);
		update(rson[o], mid+1, r[o]);
		lazy[o] = 0;
	}
	return mid;
}

void update(int o, int ll, int rr){
	if(l[o] == ll && r[o] == rr){
		lazy[o] ^= 1;
		swap(S[o][0], S[o][1]);
		return;
	}
	int mid = pushdown(o);
	if(rr <= mid)	update(lson[o], ll, rr);
	else if(ll > mid)	update(rson[o], ll, rr);
	else{
		update(lson[o], ll, mid);
		update(rson[o], mid+1, rr);
	}
	maintain(o);
}

void flip(int x){
	rep(i, 0, belong[x].size()){
		int idx = belong[x][i];
		int r = root[idx];
		ans.erase(ans.find(val[r]));
		ST[r][0].erase(ST[r][0].find(S[tree[idx]][0]));
		ST[r][1].erase(ST[r][1].find(S[tree[idx]][1]));

		update(tree[idx], info[x][i].fi, info[x][i].se);
		ST[r][0].insert(S[tree[idx]][0]);
		ST[r][1].insert(S[tree[idx]][1]);

		recal(r);
		ans.insert(val[r]);
	}
}

void init(){
	tree_id = 0;
	node_num = 0;
	clr(mk, 0);
	doit(1);
}

int main(){
	int x, y, z;
	scanf("%d", &n);
	rep(i, 1, n){
		scanf("%d %d %d", &x, &y, &z);
		V[x].pb(y, i);
		V[y].pb(x, i);
		edge[i] = z;
	}
	init();
	scanf("%d", &Q);
	while(Q--){
		scanf("%d", &x);
		flip(x);
		printf("%d\n", *ans.rbegin());
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1

using LL = long long;
using ULL = unsigned long long;
using pii = pair<int,int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 5e5 + 10;

int n, Q, dfs_cnt;
bool edge[N];
vector<pii> V[N];
int buf[N];
bool tag[N];

struct Tree{
	int lft[N], rgt[N],bottom[N], l[N<<2], r[N<<2], S[N<<2][2];
	bool lazy[N<<2];
	void dfs(int x, int fa, int dep, bool f){
		lft[x] = ++dfs_cnt;
		buf[dfs_cnt] = dep;
		tag[dfs_cnt] = f;
		for(auto p : V[x]){
			if(p.fi == fa)	continue;
			bottom[p.se] = p.fi;
			dfs(p.fi, x, dep + 1, f ^ edge[p.se]);
		}
		rgt[x] = dfs_cnt;
	}
	void build(int o, int ll, int rr){
		l[o] = ll;
		r[o] = rr;
		lazy[o] = 0;
		if(ll < rr){
			int mid = gmid;
			build(lson, ll, mid);
			build(rson, mid + 1, rr);
			S[o][0] = max(S[lson][0], S[rson][0]);
			S[o][1] = max(S[lson][1], S[rson][1]);
		} else {
			if(tag[ll]){
				S[o][0] = 0;
				S[o][1] = buf[ll];
			} else {
				S[o][0] = buf[ll];
				S[o][1] = 0;
			}
		}
	}
	int pushdown(int o){
		int mid = gmid;
		if(lazy[o]){
			update(lson, l[o], mid);
			update(rson, mid+1, r[o]);
			lazy[o] = 0;
		}
		return mid;
	}
	void update(int o, int ll, int rr){
		if(l[o] == ll && r[o] == rr){
			lazy[o] ^= 1;
			swap(S[o][0], S[o][1]);
			return;
		}
		int mid = pushdown(o);
		if(rr <= mid)	update(lson, ll, rr);
		else if(ll > mid)	update(rson, ll, rr);
		else{
			update(lson, ll, mid);
			update(rson, mid+1, rr);
		}
		S[o][0] = max(S[lson][0], S[rson][0]);
		S[o][1] = max(S[lson][1], S[rson][1]);
	}
	void init(int x){
		dfs_cnt = 0;
		dfs(x, -1, 0, 0);
		build(1, 1, n);
	}
	void flip(int x){
		x = bottom[x];
		update(1, lft[x], rgt[x]);
	}
}tree[2];

int dist[N];
int bfs(int x){
	rep(i, 1, n+1)	dist[i] = inf;
	dist[x] = 0;
	int ret = x;
	queue<int> Q;
	Q.emplace(x);
	while(!Q.empty()){
		x = Q.front(); Q.pop();
		if(dist[x] > dist[ret])	ret = x;
		for(pii p : V[x]){
			if(dist[p.fi] == inf){
				dist[p.fi] = dist[x] + 1;
				Q.emplace(p.fi);
			}
		}
	}
	return ret;
}

int main(){
	int x, y, z;
	scanf("%d", &n);
	rep(i, 1, n){
		scanf("%d %d %d", &x, &y, &z);
		V[x].pb(y, i);
		V[y].pb(x, i);
		edge[i] = z;
	}
	x = bfs(1);
	y = bfs(x);
	tree[0].init(x);
	tree[1].init(y);
	scanf("%d", &Q);
	while(Q--){
		scanf("%d", &x);
		tree[0].flip(x);
		tree[1].flip(x);
		printf("%d\n", max(tree[0].S[1][0], tree[1].S[1][0]));
	}
	return 0;
}


#include <bits/stdc++.h>
#ifdef LOCAL
#include "debuger.hpp"
#else
#define DUMP(...) 1145141919810
#define CHECK(...) (__VA_ARGS__)
#endif

int n;
const int kN = 500000 + 5;
int a[kN], b[kN];
std::vector<std::pair<int, int>> edges[kN];

struct Solver {
  int st[kN], ed[kN], stmp = 0;
  bool rev_tag[kN << 2];
  int mx[kN << 2][2];

  void insert(int p, int parity, int v, int l, int r, int rt) {
    if (l == r) {
      mx[rt][parity] = v;
      return;
    }
    int mid = l + r >> 1;
    if (p <= mid) insert(p, parity, v, l, mid, rt << 1);
    else insert(p, parity, v, mid + 1, r, rt << 1 | 1);
    up(rt);
  }

  void up(int rt) {
    mx[rt][0] = std::max(mx[rt << 1][0], mx[rt << 1 | 1][0]);
    mx[rt][1] = std::max(mx[rt << 1][1], mx[rt << 1 | 1][1]);
  }

  void down(int l, int r, int rt) {
    if (l == r || !rev_tag[rt]) return;
    rev_tag[rt] = false;
    rev(rt << 1);
    rev(rt << 1 | 1);
  }

  void rev(int rt) {
    rev_tag[rt] ^= 1;
    std::swap(mx[rt][0], mx[rt][1]);
  }

  void dfs(int u, int fa, int len, int parity) {
    st[u] = ++stmp;
    insert(st[u], parity, len, 1, n, 1);
    for (auto t : edges[u]) if (t.first != fa) {
      dfs(t.first, u, len + 1, parity ^ t.second);
    }
    ed[u] = stmp;
  }

  void reverse(int L, int R, int l, int r, int rt) {
    if (L <= l && r <= R) {
      rev(rt);
      return;
    }
    down(l, r, rt);
    int mid = l + r >> 1;
    if (L <= mid) reverse(L, R, l, mid, rt << 1);
    if (mid < R)  reverse(L, R, mid + 1, r, rt << 1 | 1);
    up(rt);
  }

  void update(int a, int b) {
    if (st[a] > st[b]) std::swap(a, b);
    reverse(st[b], ed[b], 1, n, 1);
  }
} tree[2];

int dist[kN];

int bfs(int u) {
  std::fill(dist, dist + n, -1);
  std::queue<int> que;
  que.emplace(u);
  dist[u] = 0;
  while (!que.empty()) {
    u = que.front(); que.pop();
    for (auto t : edges[u]) {
      int v = t.first;
      if (dist[v] == -1) {
        dist[v] = dist[u] + 1;
        que.emplace(v);
      }
    }
  }
  return u;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int c;
    scanf("%d%d%d", &a[i], &b[i], &c); --a[i]; --b[i];
    edges[a[i]].emplace_back(b[i], c);
    edges[b[i]].emplace_back(a[i], c);
  }
  int x = bfs(0);
  int y = bfs(x);
  tree[0].dfs(x, -1, 0, 0);
  tree[1].dfs(y, -1, 0, 0);
  int m;
  scanf("%d", &m);
  while (m--) {
    int id;
    scanf("%d", &id); --id;
    tree[0].update(a[id], b[id]);
    tree[1].update(a[id], b[id]);
    printf("%d\n", std::max(tree[0].mx[1][0], tree[1].mx[1][0]));
  }
}


#include <bits/stdc++.h>
using namespace std;
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl;
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define is_bit(x,y) (x%(1<<(y+1))>=(1<<y))
#define eror(x) cout<<#x<<'='<<(x)<<endl;
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define Gett(x,y) scanf("%d%d",&x,&y);
#define f(i,a,b) for(int i=a;i<b;i++)
#define get(x) scanf("%I64d",&x);
#define gett(x) scanf("%d",&x);
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define Add(x,y) x=(x+y)%mod
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=5e5+99;

int n,m,c,rt,fa,T[N],q[N],ans[N],h[N],a[N],s[N],t[N],edge[N][2];
vector<pair<int,int> > g[N];
int lazy[4*N];
pair<int,int> seg[4*N];

void shift(int ,int ,int );

void build(int id=1,int L=1,int R=n+1){
    if(R<=L) return ;
    if(L+1==R){
        seg[id].S=0;
        seg[id].F=h[a[L]];
        return ;
    }
    int mid=(L+R+1)>>1;
    build(id*2+0,L,mid);
    build(id*2+1,mid,R);
    seg[id].F = max(seg[id*2+0].F,seg[id*2+1].F);
    seg[id].S = max(seg[id*2+0].S,seg[id*2+1].S);
}
int query(int id,int L,int R,int l,int r){
    int res=0;
    if(R<=l || r<=L) return 0;
    if(l<=L && R<=r){
        maxm(res,seg[id].F);
        return res;
    }
    int mid=(L+R+1)>>1;
    shift(id, L, R);
    maxm(res,query(id*2+0, L, mid, l, r));
    maxm(res,query(id*2+1, mid, R, l, r));
    return res;
}
void swich(int id,int L,int R,int l,int r){
    if(R<=l || r<=L) return ;
    if(l<=L && R<=r){
        lazy[id] ^= 1;
        swap(seg[id].F,seg[id].S);
        return ;
    }
    int mid=(L+R+1)>>1;
    shift(id, L, R);
    swich(id*2+0, L, mid, l, r);
    swich(id*2+1, mid, R, l, r);
    seg[id].F = max(seg[id*2+0].F,seg[id*2+1].F);
    seg[id].S = max(seg[id*2+0].S,seg[id*2+1].S);
}
void shift(int id,int L,int R){
    int mid=(L+R+1) >> 1;
    if(lazy[id]==0) return ;
    swap(seg[id*2+0].F,seg[id*2+0].S);
    swap(seg[id*2+1].F,seg[id*2+1].S);
    lazy[id]=0;
}

//muy

void dfs1(int x,int dist,int par=0){
    if(fa<dist) fa=dist,rt=x;
    f(i,0,g[x].size())
        if(g[x][i].F!=par)
            dfs1(g[x][i].F,dist+1,x);
}
void dfs2(int x,int dist,int par){
    h[x]=dist;
    a[++c]=x;
    s[x]=c;
    f(i,0,g[x].size())
        if(g[x][i].F!=par)
            dfs2(g[x][i].F,dist+1,x);
    t[x]=c+1;
}
void solve(int rt){
    f(i,0,4*N) seg[i].F=seg[i].S=lazy[i]=0;
    c=0;
    dfs2(rt,0,0);
    build();
    f(i,1,n)
        if(T[i]){
            int u;
            if(h[edge[i][1]]<h[edge[i][0]]) u=edge[i][0];
            else u=edge[i][1];
            swich(1,1,n+1,s[u],t[u]);
        }
    f(i,0,m){
        int u;
        if(h[edge[q[i]][1]]<h[edge[q[i]][0]]) u=edge[q[i]][0];
        else u=edge[q[i]][1];
        swich(1,1,n+1,s[u],t[u]);
        maxm(ans[i],seg[1].F);
    }
}

int main(){
    cin>>n;
    f(i,1,n){
        int u,v,t;
        Gett(u,v);
        gett(t);
        T[i]=t;
        edge[i][0]=u;
        edge[i][1]=v;
        g[u].pb(mp(v,t));
        g[v].pb(mp(u,t));
    }
    cin>>m;
    f(i,0,m)
        cin>>q[i];

    fa=0;
    dfs1(1,0);
    solve(rt);

    fa=0;
    dfs1(rt,0);
    solve(rt);
    f(i,0,m) cout<<ans[i]<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl;
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define is_bit(x,y) (x%(1<<(y+1))>=(1<<y))
#define eror(x) cout<<#x<<'='<<(x)<<endl;
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define Gett(x,y) scanf("%d%d",&x,&y);
#define f(i,a,b) for(int i=a;i<b;i++)
#define get(x) scanf("%I64d",&x);
#define gett(x) scanf("%d",&x);
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define Add(x,y) x=(x+y)%mod
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=5e5+99;

int n,m,c,rt,fa,q[N],ans[N],h[N],a[N],s[N],t[N],w[N],edge[N][2];
vector<pair<int,int> > g[N];
int lazy[4*N];
pair<int,int> seg[4*N];

void shift(int ,int ,int );

void build(int id=1,int L=1,int R=n+1){
    if(R<=L) return ;
    if(L+1==R){
        seg[id].S=0;
        seg[id].F=h[a[L]];
        if(w[a[L]]) swap(seg[id].F,seg[id].S);
        return ;
    }
    int mid=(L+R+1)>>1;
    build(id*2+0,L,mid);
    build(id*2+1,mid,R);
    seg[id].F = max(seg[id*2+0].F,seg[id*2+1].F);
    seg[id].S = max(seg[id*2+0].S,seg[id*2+1].S);
}
void swich(int id,int L,int R,int l,int r){
    if(R<=l || r<=L) return ;
    if(l<=L && R<=r){
        lazy[id] ^= 1;
        swap(seg[id].F,seg[id].S);
        return ;
    }
    int mid=(L+R+1)>>1;
    shift(id, L, R);
    swich(id*2+0, L, mid, l, r);
    swich(id*2+1, mid, R, l, r);
    seg[id].F = max(seg[id*2+0].F,seg[id*2+1].F);
    seg[id].S = max(seg[id*2+0].S,seg[id*2+1].S);
}
void shift(int id,int L,int R){
    int mid=(L+R+1) >> 1;
    if(lazy[id]==0) return ;
    swich(id*2+0,L,mid,L,mid);
    swich(id*2+1,mid,R,mid,R);
    lazy[id]=0;
}

//muy
void dfs1(int x,int dist,int par=0){
    if(fa<dist) fa=dist,rt=x;
    f(i,0,g[x].size())
        if(g[x][i].F!=par)
            dfs1(g[x][i].F,dist+1,x);
}
void dfs2(int x,int dist,int par,int S){
    h[x]=dist;
    a[++c]=x;
    s[x]=c;
    f(i,0,g[x].size())
        if(g[x][i].F!=par)
            dfs2(g[x][i].F,dist+1,x,S^g[x][i].S);
    t[x]=c+1;
    w[x]=S;
}
void solve(int rt){
    f(i,0,4*N) seg[i].F=seg[i].S=lazy[i]=0;
    c=0;
    dfs2(rt,0,0,0);
    build();
    f(i,0,m){
        int u;
        if(h[edge[q[i]][1]]<h[edge[q[i]][0]]) u=edge[q[i]][0];
        else u=edge[q[i]][1];
        swich(1,1,n+1,s[u],t[u]);
        maxm(ans[i],seg[1].F);
    }
}

int main(){
    cin>>n;
    f(i,1,n){
        int u,v,t;
        Gett(u,v);
        gett(t);
        edge[i][0]=u;
        edge[i][1]=v;
        g[u].pb(mp(v,t));
        g[v].pb(mp(u,t));
    }
    cin>>m;
    f(i,0,m)
        cin>>q[i];

    fa=0;
    dfs1(1,0);
    solve(rt);

    fa=0;
    dfs1(rt,0);
    solve(rt);

    f(i,0,m) cout<<ans[i]<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl;
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define is_bit(x,y) (x%(1<<(y+1))>=(1<<y))
#define eror(x) cout<<#x<<'='<<(x)<<endl;
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define Gett(x,y) scanf("%d%d",&x,&y);
#define f(i,a,b) for(int i=a;i<b;i++)
#define get(x) scanf("%I64d",&x);
#define gett(x) scanf("%d",&x);
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define Add(x,y) x=(x+y)%mod
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=5e5+99;

int n,m,c,rt,fa,q[N],ans[N],h[N],a[N],s[N],t[N],w[N],edge[N][2];
vector<pair<int,int> > g[N];
int lazy[4*N];
pair<int,int> seg[4*N];

void shift(int ,int ,int );

void build(int id=1,int L=1,int R=n+1){
    if(R<=L) return ;
    if(L+1==R){
        seg[id].S=0;
        seg[id].F=h[a[L]];
        if(w[a[L]]) swap(seg[id].F,seg[id].S);
        return ;
    }
    int mid=(L+R+1)>>1;
    build(id*2+0,L,mid);
    build(id*2+1,mid,R);
    seg[id].F = max(seg[id*2+0].F,seg[id*2+1].F);
    seg[id].S = max(seg[id*2+0].S,seg[id*2+1].S);
}
void swich(int id,int L,int R,int l,int r){
    if(R<=l || r<=L) return ;
    if(l<=L && R<=r){
        lazy[id] ^= 1;
        swap(seg[id].F,seg[id].S);
        return ;
    }
    int mid=(L+R+1)>>1;
    shift(id, L, R);
    swich(id*2+0, L, mid, l, r);
    swich(id*2+1, mid, R, l, r);
    seg[id].F = max(seg[id*2+0].F,seg[id*2+1].F);
    seg[id].S = max(seg[id*2+0].S,seg[id*2+1].S);
}
void shift(int id,int L,int R){
    int mid=(L+R+1) >> 1;
    if(lazy[id]==0) return ;
    swich(id*2+0,L,mid,L,mid);
    swich(id*2+1,mid,R,mid,R);
    lazy[id]=0;
}

//muy

void dfs1(int x,int dist,int par=0){
    if(fa<dist) fa=dist,rt=x;
    f(i,0,g[x].size())
        if(g[x][i].F!=par)
            dfs1(g[x][i].F,dist+1,x);
}
void dfs2(int x,int dist,int par,int S){
    h[x]=dist;
    a[++c]=x;
    s[x]=c;
    f(i,0,g[x].size())
        if(g[x][i].F!=par)
            dfs2(g[x][i].F,dist+1,x,S^g[x][i].S);
    t[x]=c+1;
    w[x]=S;
}
void solve(int rt){
    f(i,0,4*N) seg[i].F=seg[i].S=lazy[i]=0;
    c=0;
    dfs2(rt,0,0,0);
    build();
    f(i,0,m){
        int u;
        if(h[edge[q[i]][1]]<h[edge[q[i]][0]]) u=edge[q[i]][0];
        else u=edge[q[i]][1];
        swich(1,1,n+1,s[u],t[u]);
        maxm(ans[i],seg[1].F);
    }
}

int main(){
    cin>>n;
    f(i,1,n){
        int u,v,t;
        Gett(u,v);
        gett(t);
        edge[i][0]=u;
        edge[i][1]=v;
        g[u].pb(mp(v,t));
        g[v].pb(mp(u,t));
    }
    cin>>m;
    f(i,0,m)
        cin>>q[i];

    fa=0;
    dfs1(1,0);
    solve(rt);

    fa=0;
    dfs1(rt,0);
    //solve(rt);

    f(i,0,m) cout<<ans[i]<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl;
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define is_bit(x,y) (x%(1<<(y+1))>=(1<<y))
#define eror(x) cout<<#x<<'='<<(x)<<endl;
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define Gett(x,y) scanf("%d%d",&x,&y);
#define f(i,a,b) for(int i=a;i<b;i++)
#define get(x) scanf("%I64d",&x);
#define gett(x) scanf("%d",&x);
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define Add(x,y) x=(x+y)%mod
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=5e5+99;

int n,m,c,rt,fa,q[N],ans[N],h[N],a[N],s[N],t[N],w[N],edge[N][2];
vector<pair<int,int> > g[N];
int lazy[4*N];
pair<int,int> seg[4*N];

void shift(int ,int ,int );

void build(int id=1,int L=1,int R=n+1){
    if(R<=L) return ;
    if(L+1==R){
        seg[id].S=0;
        seg[id].F=h[a[L]];
        if(w[a[L]]) swap(seg[id].F,seg[id].S);
        return ;
    }
    int mid=(L+R+1)>>1;
    build(id*2+0,L,mid);
    build(id*2+1,mid,R);
    seg[id].F = max(seg[id*2+0].F,seg[id*2+1].F);
    seg[id].S = max(seg[id*2+0].S,seg[id*2+1].S);
}
void swich(int id,int L,int R,int l,int r){
    if(R<=l || r<=L) return ;
    if(l<=L && R<=r){
        lazy[id] ^= 1;
        swap(seg[id].F,seg[id].S);
        return ;
    }
    int mid=(L+R+1)>>1;
    shift(id, L, R);
    swich(id*2+0, L, mid, l, r);
    swich(id*2+1, mid, R, l, r);
    seg[id].F = max(seg[id*2+0].F,seg[id*2+1].F);
    seg[id].S = max(seg[id*2+0].S,seg[id*2+1].S);
}
void shift(int id,int L,int R){
    int mid=(L+R+1) >> 1;
    if(lazy[id]==0) return ;
    swich(id*2+0,L,mid,L,mid);
    swich(id*2+1,mid,R,mid,R);
    lazy[id]=0;
}

//muy

void dfs1(int x,int dist,int par=0){
    if(fa<dist) fa=dist,rt=x;
    f(i,0,g[x].size())
        if(g[x][i].F!=par)
            dfs1(g[x][i].F,dist+1,x);
}
void dfs2(int x,int dist,int par,int S){
    h[x]=dist;
    a[++c]=x;
    s[x]=c;
    f(i,0,g[x].size())
        if(g[x][i].F!=par)
            dfs2(g[x][i].F,dist+1,x,S^g[x][i].S);
    t[x]=c+1;
    w[x]=S;
}
void solve(int rt){
    f(i,0,4*N) seg[i].F=seg[i].S=lazy[i]=0;
    c=0;
    dfs2(rt,0,0,0);
    build();
    f(i,0,m){
        int u;
        if(h[edge[q[i]][1]]<h[edge[q[i]][0]]) u=edge[q[i]][0];
        else u=edge[q[i]][1];
        swich(1,1,n+1,s[u],t[u]);
        maxm(ans[i],seg[1].F);
    }
}

int main(){
    cin>>n;
    f(i,1,n){
        int u,v,t;
        Gett(u,v);
        gett(t);
        edge[i][0]=u;
        edge[i][1]=v;
        g[u].pb(mp(v,t));
        g[v].pb(mp(u,t));
    }
    cin>>m;
    f(i,0,m)
        cin>>q[i];

    fa=0;
    dfs1(1,0);
    solve(rt);

    fa=0;
    dfs1(rt,0);
    solve(rt);

    f(i,0,m) cout<<ans[i]<<'\n';
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define db double
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(register int i = a;i <= b;++i)
#define ROF(i,a,b) for(register int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 5e5 + 5;

inline char nc(){
    #define SIZE 1000000+3
    static char buf[SIZE],*p1 = buf+SIZE,*p2 = buf+SIZE;
    if(p1 == p2){
        p1 = buf;p2 = buf+fread(buf,1,SIZE,stdin);
        if(p1 == p2) return -1;
    }
    return *p1++;
    #undef SIZE
}

template <typename T>
inline void read(T &x){
    x = 0;int flag = 0;char ch = nc();
    while(!isdigit(ch)){
        if(ch == '-') flag = 1;
        ch = nc();
    }
    while(isdigit(ch)){
        x = (x<<1) + (x<<3) + (ch^'0');
        ch = nc();
    }
    if(flag) x = -x;
}

int dep[MAXN],a[MAXN],dfn[MAXN],nfd[MAXN];

struct Edge{
    int to,w,nxt;
}e[MAXN<<1];
int head[MAXN],cnt;

inline void add(int u,int v,int w){
    e[++cnt] = (Edge){u,w,head[v]};head[v] = cnt;
}

const int MAXM = 18;
int sz[MAXN];
//int f[MAXN][MAXM+1];
int ver[MAXN<<1],tot,fir[MAXN<<1],D[MAXN<<1];
int st[MAXN<<1][MAXM+1];

inline void dfs(int v,int fa=0){
    static int ts= 0;dfn[v] = ++ts;nfd[ts] = v;
//    f[v][0] = fa;
//    FOR(i,1,MAXM){
//        f[v][i] = f[f[v][i-1]][i-1];
//    }
    dep[v] = dep[fa]+1;sz[v] = 1;
    ver[++tot] = v;fir[v] = tot;D[tot] = dep[v];
    for(int i = head[v];i;i = e[i].nxt){
        if(e[i].to == fa) continue;
        a[e[i].to] = a[v]^e[i].w;
        dfs(e[i].to,v);sz[v] += sz[e[i].to];
        ver[++tot] = v;D[tot] = dep[v];
    }
}

inline void ST(int n){
    FOR(i,1,n) st[i][0] = i;
    for(int j=1;(1<<j)<=n;j++)
        for(int i=1;i+(1<<j)-1<=n;i++)
        {
            int a=st[i][j-1];int b=st[i+(1<<(j-1))][j-1];
            st[i][j]=D[a]<D[b]?a:b;
        }
}
int pc[MAXN*2+3];
int RMQ(int l,int r)
{
    int k=pc[r-l+1];
    int a=st[l][k],b=st[r-(1<<k)+1][k];
    return D[a]<D[b]?a:b;
}
int lca(int u,int v)
{
    int x=fir[u],y=fir[v];
    if(x>y)std::swap(x,y);
    int res=RMQ(x,y);
    return ver[res];
}
/*
inline int lca(int x,int y){
    if(dep[x] != dep[y]){
        if(dep[x] < dep[y]) std::swap(x,y);
        int d = dep[x]-dep[y];
        FOR(i,0,MAXM) if((d>>i)&1) x = f[x][i];
    }
    if(x == y) return x;
    ROF(i,MAXM,0){
        if(f[x][i] == f[y][i]) continue;
        x = f[x][i],y = f[y][i];
    }
    return f[x][0];
}

*/
inline int dis(int x,int y){
    if(!x || !y) return 0;
    return dep[x]+dep[y]-2*dep[lca(x,y)];
}

struct Node{
    int x,y,d;
    Node(int x=0,int y=0) : x(x),y(y) {
        d = dis(x,y);
    }

    friend Node operator + (const Node &a,const Node &b){
        if(a.x == 0) return b;
        if(b.x == 0) return a;
        std::vector<int> S;
        S.pb(a.x);S.pb(a.y);S.pb(b.x);S.pb(b.y);
        Node ans;
        if(ans.d < a.d) ans = a;
        if(ans.d < b.d) ans = b;
        int mx = ans.d;
        FOR(i,0,1){
            FOR(j,2,3){
                int t = dis(S[i],S[j]);
                if(mx < t){
                    mx = t;
                    ans.x = S[i];ans.y = S[j];ans.d = t;
                }
            }
        }
        return ans;
    }
}c0[MAXN<<2],c1[MAXN<<2];

int rev[MAXN<<2];
#define lc ((x)<<1)
#define rc ((x)<<1|1)

inline void cover(int x){
    rev[x] ^= 1;
    std::swap(c0[x],c1[x]);
}

inline void pushdown(int x){
    if(rev[x]){
        cover(lc);
        cover(rc);
        rev[x] = 0;
        return;
    }
}

inline void pushup(int x){
    c0[x] = c0[lc]+c0[rc];
    c1[x] = c1[lc]+c1[rc];
}

inline void modify(int x,int l,int r,int L,int R){
    if(l == L && r == R){cover(x);return;}
    int mid = (l + r) >> 1;pushdown(x);
    if(R <= mid) modify(lc,l,mid,L,R);
    else if(L > mid) modify(rc,mid+1,r,L,R);
    else modify(lc,l,mid,L,mid),modify(rc,mid+1,r,mid+1,R);
    pushup(x);
}

inline void build(int x,int l,int r){
    if(l == r){
        if(a[nfd[l]]) c1[x] = Node(nfd[l],nfd[l]);
        else c0[x] = Node(nfd[l],nfd[l]);
        return;
    }
    int mid = (l + r) >> 1;
    build(lc,l,mid);build(rc,mid+1,r);
    pushup(x);
}

int n;

int uu[MAXN],vv[MAXN];
int main(){
    pc[0] = -1;FOR(i,1,2*MAXN-1) pc[i] = pc[i>>1]+1;
    read(n);
    FOR(i,1,n-1){
        int u,v,w;read(u);read(v);read(w);
        uu[i] = u;vv[i] = v;
        add(u,v,w);add(v,u,w);
    }
    dfs(1);
    ST(2*n-1);
    build(1,1,n);
    int q;read(q);
    FOR(i,1,n-1) if(dep[uu[i]] < dep[vv[i]]) std::swap(uu[i],vv[i]);
    FOR(i,1,q){
        int x;read(x);
        modify(1,1,n,dfn[uu[x]],dfn[uu[x]]+sz[uu[x]]-1);
        int ans = std::max(c0[1].d,c1[1].d);
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define db double
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(register int i = a;i <= b;++i)
#define ROF(i,a,b) for(register int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 5e5 + 5;

inline char nc(){
    #define SIZE 1000000+3
    static char buf[SIZE],*p1 = buf+SIZE,*p2 = buf+SIZE;
    if(p1 == p2){
        p1 = buf;p2 = buf+fread(buf,1,SIZE,stdin);
        if(p1 == p2) return -1;
    }
    return *p1++;
    #undef SIZE
}

template <typename T>
inline void read(T &x){
    x = 0;int flag = 0;char ch = nc();
    while(!isdigit(ch)){
        if(ch == '-') flag = 1;
        ch = nc();
    }
    while(isdigit(ch)){
        x = (x<<1) + (x<<3) + (ch^'0');
        ch = nc();
    }
    if(flag) x = -x;
}

int dep[MAXN],a[MAXN],dfn[MAXN],nfd[MAXN];

struct Edge{
    int to,w,nxt;
}e[MAXN<<1];
int head[MAXN],cnt;

inline void add(int u,int v,int w){
    e[++cnt] = (Edge){u,w,head[v]};head[v] = cnt;
}

const int MAXM = 17;
int sz[MAXN];
//int f[MAXN][MAXM+1];
int ver[MAXN<<1],tot,fir[MAXN<<1],D[MAXN<<1];
int st[MAXN<<1][MAXM+1];

inline void dfs(int v,int fa=0){
    static int ts= 0;dfn[v] = ++ts;nfd[ts] = v;
//    f[v][0] = fa;
//    FOR(i,1,MAXM){
//        f[v][i] = f[f[v][i-1]][i-1];
//    }
    dep[v] = dep[fa]+1;sz[v] = 1;
    ver[++tot] = v;fir[v] = tot;D[tot] = dep[v];
    for(int i = head[v];i;i = e[i].nxt){
        if(e[i].to == fa) continue;
        a[e[i].to] = a[v]^e[i].w;
        dfs(e[i].to,v);sz[v] += sz[e[i].to];
        ver[++tot] = v;D[tot] = dep[v];
    }
}

inline void ST(int n){
    FOR(i,1,n) st[i][0] = i;
    for(int j=1;(1<<j)<=n;j++)
        for(int i=1;i+(1<<j)-1<=n;i++)
        {
            int a=st[i][j-1];int b=st[i+(1<<(j-1))][j-1];
            st[i][j]=D[a]<D[b]?a:b;
        }
}
int pc[MAXN*2+3];
int RMQ(int l,int r)
{
    int k=pc[r-l+1];
    int a=st[l][k],b=st[r-(1<<k)+1][k];
    return D[a]<D[b]?a:b;
}
int lca(int u,int v)
{
    int x=fir[u],y=fir[v];
    if(x>y)std::swap(x,y);
    int res=RMQ(x,y);
    return ver[res];
}
/*
inline int lca(int x,int y){
    if(dep[x] != dep[y]){
        if(dep[x] < dep[y]) std::swap(x,y);
        int d = dep[x]-dep[y];
        FOR(i,0,MAXM) if((d>>i)&1) x = f[x][i];
    }
    if(x == y) return x;
    ROF(i,MAXM,0){
        if(f[x][i] == f[y][i]) continue;
        x = f[x][i],y = f[y][i];
    }
    return f[x][0];
}

*/
inline int dis(int x,int y){
    if(!x || !y) return 0;
    return dep[x]+dep[y]-2*dep[lca(x,y)];
}

struct Node{
    int x,y,d;
    Node(int x=0,int y=0) : x(x),y(y) {
        d = dis(x,y);
    }

    friend Node operator + (const Node &a,const Node &b){
        if(a.x == 0) return b;
        if(b.x == 0) return a;
        std::vector<int> S;
        S.pb(a.x);S.pb(a.y);S.pb(b.x);S.pb(b.y);
        Node ans;
        if(ans.d < a.d) ans = a;
        if(ans.d < b.d) ans = b;
        int mx = ans.d;
        FOR(i,0,1){
            FOR(j,2,3){
                int t = dis(S[i],S[j]);
                if(mx < t){
                    mx = t;
                    ans.x = S[i];ans.y = S[j];ans.d = t;
                }
            }
        }
        return ans;
    }
}c0[MAXN<<2],c1[MAXN<<2];

int rev[MAXN<<2];
#define lc ((x)<<1)
#define rc ((x)<<1|1)

inline void cover(int x){
    rev[x] ^= 1;
    std::swap(c0[x],c1[x]);
}

inline void pushdown(int x){
    if(rev[x]){
        cover(lc);
        cover(rc);
        rev[x] = 0;
        return;
    }
}

inline void pushup(int x){
    c0[x] = c0[lc]+c0[rc];
    c1[x] = c1[lc]+c1[rc];
}

inline void modify(int x,int l,int r,int L,int R){
    if(l == L && r == R){cover(x);return;}
    int mid = (l + r) >> 1;pushdown(x);
    if(R <= mid) modify(lc,l,mid,L,R);
    else if(L > mid) modify(rc,mid+1,r,L,R);
    else modify(lc,l,mid,L,mid),modify(rc,mid+1,r,mid+1,R);
    pushup(x);
}

inline void build(int x,int l,int r){
    if(l == r){
        if(a[nfd[l]]) c1[x] = Node(nfd[l],nfd[l]);
        else c0[x] = Node(nfd[l],nfd[l]);
        return;
    }
    int mid = (l + r) >> 1;
    build(lc,l,mid);build(rc,mid+1,r);
    pushup(x);
}

int n;

int uu[MAXN],vv[MAXN];
int main(){
    pc[0] = -1;FOR(i,1,2*MAXN-1) pc[i] = pc[i>>1]+1;
    read(n);
    FOR(i,1,n-1){
        int u,v,w;read(u);read(v);read(w);
        uu[i] = u;vv[i] = v;
        add(u,v,w);add(v,u,w);
    }
    dfs(1);
    ST(2*n-1);
    build(1,1,n);
    int q;read(q);
    FOR(i,1,n-1) if(dep[uu[i]] < dep[vv[i]]) std::swap(uu[i],vv[i]);
    FOR(i,1,q){
        int x;read(x);
        modify(1,1,n,dfn[uu[x]],dfn[uu[x]]+sz[uu[x]]-1);
        int ans = std::max(c0[1].d,c1[1].d);
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define db double
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 5e5 + 5;
int n;

struct Edge{
    int to,w,nxt;
}e[MAXN<<1];
int head[MAXN],cnt;

struct DS{
    int mx0[MAXN<<2],mx1[MAXN<<2],tag[MAXN<<2];
    int dfn[MAXN],nfd[MAXN],dep[MAXN],col[MAXN],sz[MAXN],ts = 0;
    #define lc ((x)<<1)
    #define rc ((x)<<1|1)

    inline void pushup(int x){
        mx0[x] = std::max(mx0[lc],mx0[rc]);
        mx1[x] = std::max(mx1[lc],mx1[rc]);
    }

    inline void build(int x,int l,int r){
        if(l == r){
            mx0[x] = mx1[x] = 0;
            if(col[nfd[l]]) mx1[x] = dep[nfd[l]];
            else mx0[x] = dep[nfd[l]];
            return;
        }
        int mid = (l + r) >> 1;
        build(lc,l,mid);build(rc,mid+1,r);
        pushup(x);
    }

    inline void cover(int x){
        tag[x] ^= 1;std::swap(mx0[x],mx1[x]);
    }

    inline void pushdown(int x){
        if(tag[x]){
            cover(lc);cover(rc);tag[x] = 0;
        }
    }

    inline void modify(int x,int l,int r,int L,int R){
        if(l == L && r == R) return cover(x);
        int mid = (l + r) >> 1;pushdown(x);
        if(R <= mid) modify(lc,l,mid,L,R);
        else if(L > mid) modify(rc,mid+1,r,L,R);
        else modify(lc,l,mid,L,mid),modify(rc,mid+1,r,mid+1,R);
        pushup(x);
    }

    inline void dfs(int v,int fa=0){
        dfn[v] = ++ts;nfd[ts] = v;
        dep[v] = dep[fa]+1;sz[v] = 1;
        for(int i = head[v];i;i = e[i].nxt){
            if(e[i].to == fa) continue;
            col[e[i].to] = col[v]^e[i].w;
            dfs(e[i].to,v);sz[v] += sz[e[i].to];
        }
    }

    inline void update(int u,int v){
        if(dep[u] > dep[v]) std::swap(u,v);
        modify(1,1,n,dfn[v],dfn[v]+sz[v]-1);
    }
}ds1,ds2;

inline int get(int rt){
    int mx = 0,ps = -1;
    std::function<void(int,int,int)> dfs = [&](int v,int fa,int dep){
        if(dep > mx){
            mx = dep;
            ps = v;
        }
        for(int i = head[v];i;i = e[i].nxt){
            if(e[i].to == fa) continue;
            dfs(e[i].to,v,dep+1);
        }
    };
    dfs(rt,0,1);
    return ps;
}

int uu[MAXN],vv[MAXN];

int main(){
    scanf("%d",&n);
    FOR(i,1,n-1){
        int u,v,w;scanf("%d%d%d",&u,&v,&w);uu[i] = u;vv[i] = v;
        auto add = [&](int u,int v,int w){
            e[++cnt] = (Edge){v,w,head[u]};head[u] = cnt;
            e[++cnt] = (Edge){u,w,head[v]};head[v] = cnt;
        };
        add(u,v,w);
    }
    int q;scanf("%d",&q);
    int r1 = get(1),r2 = get(r1);
    ds1.dfs(r1);ds1.build(1,1,n);
    ds2.dfs(r2);ds2.build(1,1,n);
    while(q--){
        int x;scanf("%d",&x);
        ds1.update(uu[x],vv[x]);ds2.update(uu[x],vv[x]);
        printf("%d\n",std::max(ds1.mx0[1],ds2.mx0[1])-1);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 100000;
int n, q;
int u[mxn], v[mxn], w[mxn];
int l[mxn], r[mxn], d[mxn], f[mxn];
vector<int> id;
vector<int> g[mxn];

struct segTree{
	int l, r;
	segTree *tl, *tr;
	struct T{
		int p[2] = {0}, w = 0, x[2] = {0}, y[2] = {0}, z[2] = {0}, l = 0;

		friend T operator+(T l, T r){
			T f;
			for(int i = 0; i < 2; i++){
				f.p[i] = max(l.p[i], r.p[i]);
				f.w = max(l.w, r.w);
				f.x[i] = max({l.x[i], r.x[i], l.p[i] + r.w});
				f.y[i] = max({l.y[i], r.y[i], l.w + r.p[i]});
				f.z[i] = max({l.z[i], r.z[i], l.x[i] + r.p[i], l.p[i] + r.y[i]});
			}
			return f;
		}
	}val;

	segTree(int a, int b){
		l = a, r = b;
		if(l != r){
			int mid = (l + r) / 2;
			tl = new segTree(l, mid);
			tr = new segTree(mid + 1, r);
			val = tl->val + tr->val;
		}else{
			int it = id[l];
			val.p[f[it]] = val.z[f[it]] = d[it];
			val.x[f[it]] = val.y[f[it]] = -d[it];
			val.w = val.x[!f[it]] = val.y[!f[it]] = -2 * d[it];
		}
	}

	void upd(){
		val.l ^= 1;
		swap(val.p[0], val.p[1]);
		swap(val.x[0], val.x[1]);
		swap(val.y[0], val.y[1]);
		swap(val.z[0], val.z[1]);
	}

	void add(int a, int b){
		if(b < l || r < a) return;
		if(a <= l && r <= b) return upd();
		if(val.l) tl->upd(), tr->upd(), val.l = 0;
		tl->add(a, b), tr->add(a, b);
		val = tl->val + tr->val;
	}
};

void dfs(int c, int p){
	l[c] = id.size();
	id.push_back(c);
	for(int i : g[c]) if(i != p){
		if(v[i] == c) swap(u[i], v[i]);
		d[v[i]] = d[c] + 1, f[v[i]] = f[c] ^ w[i];
		dfs(v[i], i);
		id.push_back(c);
	}
	r[c] = id.size() - 1;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;

	for(int i = 0; i < n - 1; i++){
		cin >> u[i] >> v[i] >> w[i];
		g[--u[i]].push_back(i);
		g[--v[i]].push_back(i);
	}

	dfs(0, -1);
	segTree tre(0, id.size() - 1);

	cin >> q;

	while(q--){
		int x;
		cin >> x;
		x--;
		tre.add(l[v[x]], r[v[x]]);
		cout << max(tre.val.z[0], tre.val.z[1]) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 100000;
int n, q;
int u[mxn], v[mxn], w[mxn];
int l[mxn], r[mxn], d[mxn], f[mxn];
vector<int> g[mxn];

struct segTree{
	int l, r;
	segTree *tl, *tr;
	struct T{
		ll p[2] = {0}, w[2] = {0}, x[2] = {0}, y[2] = {0}, z[2] = {0};

		friend T operator+(T l, T r){
			T f;
			for(int i = 0; i < 2; i++){
				f.p[i] = max(l.p[i], r.p[i]);
				f.w[i] = max(l.w[i], r.w[i]);
				f.x[i] = max({l.x[i], r.x[i], l.p[i] + r.w[i]});
				f.y[i] = max({l.y[i], r.y[i], l.w[i] + r.p[i]});
				f.z[i] = max({l.z[i], r.z[i], l.x[i] + r.p[i], l.p[i] + r.y[i]});
			}
			return f;
		}
	}val;

	segTree(int a, int b){
		l = a, r = b;
		if(l != r){
			int mid = (l + r) / 2;
			tl = new segTree(l, mid);
			tr = new segTree(mid + 1, r);
			val = tl->val  + tr->val;
		}else{
			val.w[f[l]] = -2 * d[l];
			val.p[f[l]] = val.z[f[l]] = d[l];
			val.x[f[l]] = val.y[f[l]] = -d[l];
		}
	}

	void add(int a, int b){
		if(b < l || r < a) return;
		if(a <= l && r <= b){
			swap(val.p[0], val.p[1]);
			swap(val.w[0], val.w[1]);
			swap(val.x[0], val.x[1]);
			swap(val.y[0], val.y[1]);
			swap(val.z[0], val.z[1]);
			return;
		}
		tl->add(a, b), tr->add(a, b);
		val = tl->val + tr->val;
	}
};

int dfs(int c, int p){
	r[c] = l[c];
	for(int i : g[c]) if(i != p){
		if(v[i] == c) swap(u[i], v[i]);
		l[v[i]] = r[c] + 1, d[v[i]] = d[c] + 1, f[v[i]] = f[c] ^ w[i];
		r[c] = dfs(v[i], i);
	}
	return r[c];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;

	for(int i = 0; i < n - 1; i++){
		cin >> u[i] >> v[i] >> w[i];
		g[--u[i]].push_back(i);
		g[--v[i]].push_back(i);
	}

	dfs(0, -1);
	segTree tre(0, n - 1);

	cin >> q;

	while(q--){
		int x;
		cin >> x;
		x--;
		tre.add(l[v[x]], r[v[x]]);
		cout << max(tre.val.z[0], tre.val.z[1]) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 500000;
int n, q;
int u[mxn], v[mxn], w[mxn];
int l[mxn], r[mxn], d[mxn], f[mxn];
vector<int> id;
vector<int> g[mxn];

struct segTree{
	int l, r;
	segTree *tl, *tr;
	struct T{
		int p[2] = {0}, w = 0, x[2] = {0}, y[2] = {0}, z[2] = {0}, lz = 0;

		friend T operator+(T l, T r){
			T f;
			for(int i = 0; i < 2; i++){
				f.p[i] = max(l.p[i], r.p[i]);
				f.w = max(l.w, r.w);
				f.x[i] = max({l.x[i], r.x[i], l.p[i] + r.w});
				f.y[i] = max({l.y[i], r.y[i], l.w + r.p[i]});
				f.z[i] = max({l.z[i], r.z[i], l.x[i] + r.p[i], l.p[i] + r.y[i]});
			}
			return f;
		}
	}val;

	segTree(int a, int b){
		l = a, r = b;
		if(l != r){
			int mid = (l + r) / 2;
			tl = new segTree(l, mid);
			tr = new segTree(mid + 1, r);
			val = tl->val + tr->val;
		}else{
			int it = id[l];
			val.w = -2 * d[it];
			val.p[f[it]] = d[it];
			val.x[f[it]] = val.y[f[it]] = -d[it];
			val.p[!f[it]] = val.x[!f[it]] = val.y[!f[it]] = 0xcfcfcfcf;
		}
	}

	void upd(){
		val.lz ^= 1;
		swap(val.p[0], val.p[1]);
		swap(val.x[0], val.x[1]);
		swap(val.y[0], val.y[1]);
		swap(val.z[0], val.z[1]);
	}

	void add(int a, int b){
		if(b < l || r < a) return;
		if(a <= l && r <= b) return upd();
		if(val.lz) tl->upd(), tr->upd(), val.lz = 0;
		tl->add(a, b), tr->add(a, b);
		val = tl->val + tr->val;
	}
};

void dfs(int c, int p){
	l[c] = id.size();
	id.push_back(c);
	for(int i : g[c]) if(i != p){
		if(v[i] == c) swap(u[i], v[i]);
		d[v[i]] = d[c] + 1, f[v[i]] = f[c] ^ w[i];
		dfs(v[i], i);
		id.push_back(c);
	}
	r[c] = id.size() - 1;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;

	for(int i = 0; i < n - 1; i++){
		cin >> u[i] >> v[i] >> w[i];
		g[--u[i]].push_back(i);
		g[--v[i]].push_back(i);
	}

	dfs(0, -1);
	segTree tre(0, id.size() - 1);

	cin >> q;

	while(q--){
		int x;
		cin >> x;
		x--;
		tre.add(l[v[x]], r[v[x]]);
		cout << max(tre.val.z[0], tre.val.z[1]) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 500000;
int n, q;
int u[mxn], v[mxn], w[mxn];
int l[mxn], r[mxn], d[mxn], f[mxn];
vector<int> id;
vector<int> g[mxn];

struct segTree{
	int l, r;
	segTree *tl, *tr;
	struct T{
		int p[2] = {0}, w = 0, x[2] = {0}, y[2] = {0}, z[2] = {0}, lz = 0;

		friend T operator+(T l, T r){
			T f;
			for(int i = 0; i < 2; i++){
				f.p[i] = max(l.p[i], r.p[i]);
				f.w = max(l.w, r.w);
				f.x[i] = max({l.x[i], r.x[i], l.p[i] + r.w});
				f.y[i] = max({l.y[i], r.y[i], l.w + r.p[i]});
				f.z[i] = max({l.z[i], r.z[i], l.x[i] + r.p[i], l.p[i] + r.y[i]});
			}
			return f;
		}
	}val;

	segTree(int a, int b){
		l = a, r = b;
		if(l != r){
			int mid = (l + r) / 2;
			tl = new segTree(l, mid);
			tr = new segTree(mid + 1, r);
			val = tl->val + tr->val;
		}else{
			int it = id[l];
			val.w = -2 * d[it];
			val.p[f[it]] = d[it];
			val.x[f[it]] = val.y[f[it]] = -d[it];
			val.p[!f[it]] = val.x[!f[it]] = val.y[!f[it]] = 0xcfcfcfcf;
		}
	}

	void pr(){
		cout << l << " " << r << endl;
		for(int i = l; i <= r; i++) cout << id[i] + 1 << " ";
		cout << endl;
		for(int i = 0; i < 2; i++){
			cout << val.p[i] << " " << val.w << " " << val.x[i] << " ";
			cout << val.y[i] << " " << val.z[i] << endl;
		}
		cout << endl;
	}

	void upd(){
		val.lz ^= 1;
		swap(val.p[0], val.p[1]);
		swap(val.x[0], val.x[1]);
		swap(val.y[0], val.y[1]);
		swap(val.z[0], val.z[1]);
	}

	void add(int a, int b){
		if(b < l || r < a) return;
		if(a <= l && r <= b) return upd();
		if(val.lz) tl->upd(), tr->upd(), val.lz = 0;
		tl->add(a, b), tr->add(a, b);
		val = tl->val + tr->val;
		//pr();
	}
};

void dfs(int c, int p){
	l[c] = id.size();
	id.push_back(c);
	for(int i : g[c]) if(i != p){
		if(v[i] == c) swap(u[i], v[i]);
		d[v[i]] = d[c] + 1, f[v[i]] = f[c] ^ w[i];
		dfs(v[i], i);
		id.push_back(c);
	}
	r[c] = id.size() - 1;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;

	for(int i = 0; i < n - 1; i++){
		cin >> u[i] >> v[i] >> w[i];
		g[--u[i]].push_back(i);
		g[--v[i]].push_back(i);
	}

	dfs(0, -1);
	segTree tre(0, id.size() - 1);

	cin >> q;

	while(q--){
		int x;
		cin >> x;
		x--;
		//cout << v[x] + 1 << endl << endl;
		tre.add(l[v[x]], r[v[x]]);
		cout << max(tre.val.z[0], tre.val.z[1]) << endl;
		//cout << endl << "------------------------------------" << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1

using LL = long long;
using ULL = unsigned long long;
using pii = pair<int,int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 5e5 + 10;

int n, Q, dfs_cnt;
bool edge[N];
vector<pii> V[N];
pii buf[N];

struct Tree{
	int lft[N], rgt[N],bottom[N], l[N<<2], r[N<<2], S[N<<2][2];
	bool lazy[N<<2];
	void dfs(int x, int fa, int dep, bool f){
		lft[x] = ++dfs_cnt;
		buf[dfs_cnt] = mp(dep, f);
		for(auto p : V[x]){
			if(p.fi == fa)	continue;
			bottom[p.se] = p.fi;
			dfs(p.fi, x, dep + 1, f ^ edge[p.se]);
		}
		rgt[x] = dfs_cnt;
	}
	void maintain(int o){
		S[o][0] = max(S[lson][0], S[rson][0]);
		S[o][1] = max(S[lson][1], S[rson][1]);
	}
	void build(int o, int ll, int rr){
		l[o] = ll;
		r[o] = rr;
		lazy[o] = 0;
		if(ll < rr){
			int mid = gmid;
			build(lson, ll, mid);
			build(rson, mid+1, rr);
			maintain(o);
		} else {
			if(buf[ll].se){
				S[o][0] = 0;
				S[o][1] = buf[ll].fi;
			} else {
				S[o][0] = buf[ll].fi;
				S[o][1] = 0;
			}
		}
	}
	int pushdown(int o){
		int mid = gmid;
		if(lazy[o]){
			update(lson, l[o], mid);
			update(rson, mid+1, r[o]);
			lazy[o] = 0;
		}
		return mid;
	}
	void update(int o, int ll, int rr){
		if(l[o] == ll && r[o] == rr){
			lazy[o] ^= 1;
			swap(S[o][0], S[o][1]);
			return;
		}
		int mid = pushdown(o);
		if(rr <= mid)	update(lson, ll, rr);
		else if(ll > mid)	update(rson, ll, rr);
		else{
			update(lson, ll, mid);
			update(rson, mid+1, rr);
		}
		maintain(o);
	}
	void init(int x){
		dfs_cnt = 0;
		dfs(x, -1, 0, 0);
		build(1, 1, n);
	}
	void flip(int x){
		x = bottom[x];
		update(1, lft[x], rgt[x]);
	}
}tree[2];

int dist[N];
int bfs(int x){
	rep(i, 1, n+1)	dist[i] = inf;
	dist[x] = 0;
	int ret = x;
	queue<int> Q;
	Q.emplace(x);
	while(!Q.empty()){
		x = Q.front(); Q.pop();
		if(dist[x] > dist[ret])	ret = x;
		for(pii p : V[x]){
			if(dist[p.fi] == inf){
				dist[p.fi] = dist[x] + 1;
				Q.emplace(p.fi);
			}
		}
	}
	return ret;
}

void init(){
	int x = bfs(1);
	int y = bfs(x);
	tree[0].init(x);
	tree[1].init(y);
}

int main(){
	int x, y, z;
	scanf("%d", &n);
	rep(i, 1, n){
		scanf("%d %d %d", &x, &y, &z);
		V[x].pb(y, i);
		V[y].pb(x, i);
		edge[i] = z;
	}
	init();
	scanf("%d", &Q);
	while(Q--){
		scanf("%d", &x);
		tree[0].flip(x);
		tree[1].flip(x);
		printf("%d\n", max(tree[0].S[1][0], tree[1].S[1][0]));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

namespace io{
	const int size=1<<22|1;
	char iBuf[size],*iS,*iT,c;
	char oBuf[size],*oS=oBuf,*oT=oBuf+size;
	#define getc() (iS==iT?iT=iBuf+fread(iS=iBuf,1,size,stdin),(iS==iT?EOF:(*iS++)):(*iS++))
	template<class T>void qread(T &x){
		int f=1;
		for(c=getc();c<'0'||c>'9';c=getc())
			if(c=='-')f=-1;
		for(x=0;c>='0'&&c<='9';c=getc())
			x=(x<<3)+(x<<1)+(c&15);
		x*=f;
	}
	void flush(){
		fwrite(oBuf,1,oS-oBuf,stdout);
		oS=oBuf;
	}
	void putc(char x){
		*oS++=x;
		if(oS==oT)flush();
	}
	template<class T>void qwrite(T x){
		static char qu[55];
		char *tmp=qu;
		do *tmp++=(x%10)^'0';while(x/=10);
		while(tmp--!=qu)putc(*tmp);
	}
	struct flusher{
		~flusher(){flush();}
	}_;
}

const int maxn=500005;
int n,q,k,t;
int dfn[maxn],vis[maxn*2],dep[maxn],w[maxn],ver[maxn];
int dfnL[maxn],dfnR[maxn],pos[maxn],tp[maxn];
vector<pair<int,int> >edge[maxn];

namespace ST{
	const int mlog=20;
	int lg2[maxn*2];
	pair<int,int>mn[maxn*2][mlog];
	void init(){
		for(int i=2;i<=k;i++)lg2[i]=lg2[i>>1]+1;
		for(int i=1;i<=k;i++)mn[i][0]=make_pair(dep[vis[i]],vis[i]);
		for(int j=1;j<mlog;j++)for(int i=1;i<=k;i++)if(i+(1<<j)-1<=k)
			mn[i][j]=min(mn[i][j-1],mn[i+(1<<j-1)][j-1]);
	}
	int qry(int l,int r){
		if(l>r)swap(l,r);
		int len=lg2[r-l+1];
		return min(mn[l][len],mn[r-(1<<len)+1][len]).second;
	}
}
int dist(int x,int y){
	int z=ST::qry(dfn[x],dfn[y]);
	return dep[x]+dep[y]-2*dep[z];
}

class Diam{
public:
	int u,v,d;
	Diam():u(0),v(0),d(0){}
	Diam(int _u):u(_u),v(_u),d(0){}
	Diam operator+(const Diam &o)const{
		if(u==0)return o;
		if(o.u==0)return *this;
		Diam res=*this;
		if(o.d>res.d)res=o;
		int uu=dist(u,o.u),uv=dist(u,o.v),vu=dist(v,o.u),vv=dist(v,o.v);
		int mx=max(max(uu,uv),max(vu,vv));
		if(mx<=res.d)return res;
		res.d=mx;
		if(uu==res.d)res.u=u,res.v=o.u;
		else if(uv==res.d)res.u=u,res.v=o.v;
		else if(vu==res.d)res.u=v,res.v=o.u;
		else res.u=v,res.v=o.v;
		return res;
	}
};
class Info{
public:
	Diam val0,val1;
	Info():val0(Diam()),val1(Diam()){}
	Info operator+(const Info &o){
		Info res;
		res.val0=val0+o.val0;
		res.val1=val1+o.val1;
		return res;
	}
};
namespace Segtree{
	bool tag[maxn*4];
	Info t[maxn*4];
	void apply(int cur){
		tag[cur]^=1;
		swap(t[cur].val0,t[cur].val1);
	}
	void pushdown(int cur){
		if(tag[cur]){
			apply(cur<<1);
			apply(cur<<1|1);
			tag[cur]=false;
		}
	}
	void pushup(int cur){
		t[cur]=t[cur<<1]+t[cur<<1|1];
	}
	void build(int cur,int l,int r){
		if(l==r){
			if(tp[pos[l]]==0)t[cur].val0=Diam(pos[l]);
			else t[cur].val1=Diam(pos[l]);
			return;
		}
		int mid=l+r>>1;
		build(cur<<1,l,mid);
		build(cur<<1|1,mid+1,r);
		pushup(cur);
	}
	void update(int cur,int l,int r,int vl,int vr){
		if(l>=vl&&r<=vr){
			apply(cur);
			return;
		}
		pushdown(cur);
		int mid=l+r>>1;
		if(mid>=vl)update(cur<<1,l,mid,vl,vr);
		if(mid<vr)update(cur<<1|1,mid+1,r,vl,vr);
		pushup(cur);
	}
	int query(){
		return max(t[1].val0.d,t[1].val1.d);
	}
}

void dfs(int x,int p,int d,int f){
	dfn[x]=++k;
	vis[k]=x;
	dfnL[x]=++t;
	pos[t]=x;
	dep[x]=d;
	tp[x]=f;
	for(int i=0;i<int(edge[x].size());i++){
		pair<int,int>y=edge[x][i];
		if(y.first==p)continue;
		dfs(y.first,x,d+1,f^w[y.second]);
		ver[y.second]=y.first;
		vis[++k]=x;
	}
	dfnR[x]=t;
}

int main(){
	io::qread(n);
	for(int i=1;i<=n-1;i++){
		int u,v;
		io::qread(u);io::qread(v);io::qread(w[i]);
		edge[u].push_back(make_pair(v,i));
		edge[v].push_back(make_pair(u,i));
	}
	dfs(1,0,0,0);
	ST::init();
	Segtree::build(1,1,n);
	io::qread(q);
	while(q--){
		int e;
		io::qread(e);
		Segtree::update(1,1,n,dfnL[ver[e]],dfnR[ver[e]]);
		io::qwrite(Segtree::query());
		io::putc('\n');
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int maxn=500005;
int n,q,k,t;
int dfn[maxn],vis[maxn*2],dep[maxn],w[maxn],ver[maxn];
int dfnL[maxn],dfnR[maxn],pos[maxn],tp[maxn];
vector<pair<int,int> >edge[maxn];

namespace ST{
	const int mlog=20;
	int lg2[maxn*2];
	pair<int,int>mn[maxn*2][mlog];
	void init(){
		for(int i=2;i<=k;i++)lg2[i]=lg2[i>>1]+1;
		for(int i=1;i<=k;i++)mn[i][0]=make_pair(dep[vis[i]],vis[i]);
		for(int j=1;j<mlog;j++)for(int i=1;i<=k;i++)if(i+(1<<j)-1<=k)
			mn[i][j]=min(mn[i][j-1],mn[i+(1<<j-1)][j-1]);
	}
	int qry(int l,int r){
		if(l>r)swap(l,r);
		int len=lg2[r-l+1];
		return min(mn[l][len],mn[r-(1<<len)+1][len]).second;
	}
}
int dist(int x,int y){
	int z=ST::qry(dfn[x],dfn[y]);
	return dep[x]+dep[y]-2*dep[z];
}

class Diam{
public:
	int u,v,d;
	Diam():u(0),v(0),d(0){}
	Diam(int _u):u(_u),v(_u),d(0){}
	Diam operator+(const Diam &o)const{
		if(u==0)return o;
		if(o.u==0)return *this;
		Diam res=*this;
		if(o.d>res.d)res=o;
		int uu=dist(u,o.u),uv=dist(u,o.v),vu=dist(v,o.u),vv=dist(v,o.v);
		res.d=max(res.d,max(max(uu,uv),max(vu,vv)));
		if(uu==res.d)res.u=u,res.v=o.u;
		else if(uv==res.d)res.u=u,res.v=o.v;
		else if(vu==res.d)res.u=v,res.v=o.u;
		else res.u=v,res.v=o.v;
		return res;
	}
};
class Info{
public:
	Diam val0,val1;
	Info():val0(Diam()),val1(Diam()){}
	Info operator+(const Info &o){
		Info res;
		res.val0=val0+o.val0;
		res.val1=val1+o.val1;
		return res;
	}
};
namespace Segtree{
	bool tag[maxn*4];
	Info t[maxn*4];
	void apply(int cur){
		tag[cur]^=1;
		swap(t[cur].val0,t[cur].val1);
	}
	void pushdown(int cur){
		if(tag[cur]){
			apply(cur<<1);
			apply(cur<<1|1);
			tag[cur]=false;
		}
	}
	void pushup(int cur){
		t[cur]=t[cur<<1]+t[cur<<1|1];
	}
	void build(int cur,int l,int r){
		if(l==r){
			if(tp[pos[l]]==0)t[cur].val0=Diam(pos[l]);
			else t[cur].val1=Diam(pos[l]);
			return;
		}
		int mid=l+r>>1;
		build(cur<<1,l,mid);
		build(cur<<1|1,mid+1,r);
		pushup(cur);
	}
	void update(int cur,int l,int r,int vl,int vr){
		if(l>=vl&&r<=vr){
			apply(cur);
			return;
		}
		pushdown(cur);
		int mid=l+r>>1;
		if(mid>=vl)update(cur<<1,l,mid,vl,vr);
		if(mid<vr)update(cur<<1|1,mid+1,r,vl,vr);
		pushup(cur);
	}
	int query(){
		return max(t[1].val0.d,t[1].val1.d);
	}
}

void dfs(int x,int p,int d,int f){
	dfn[x]=++k;
	vis[k]=x;
	dfnL[x]=++t;
	pos[t]=x;
	dep[x]=d;
	tp[x]=f;
	for(int i=0;i<int(edge[x].size());i++){
		pair<int,int>y=edge[x][i];
		if(y.first==p)continue;
		dfs(y.first,x,d+1,f^w[y.second]);
		ver[y.second]=y.first;
		vis[++k]=x;
	}
	dfnR[x]=t;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++){
		int u,v;
		scanf("%d%d%d",&u,&v,&w[i]);
		edge[u].push_back(make_pair(v,i));
		edge[v].push_back(make_pair(u,i));
	}
	dfs(1,0,0,0);
	ST::init();
	Segtree::build(1,1,n);
	scanf("%d",&q);
	while(q--){
		int e;
		scanf("%d",&e);
		Segtree::update(1,1,n,dfnL[ver[e]],dfnR[ver[e]]);
		printf("%d\n",Segtree::query());
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int maxn=500005;
int n,q,k,t;
int dfn[maxn],vis[maxn*2],dep[maxn],w[maxn],ver[maxn];
int dfnL[maxn],dfnR[maxn],pos[maxn],tp[maxn];
vector<pair<int,int> >edge[maxn];

namespace ST{
	const int mlog=20;
	int lg2[maxn*2];
	pair<int,int>mn[maxn*2][mlog];
	void init(){
		for(int i=2;i<=k;i++)lg2[i]=lg2[i>>1]+1;
		for(int i=1;i<=k;i++)mn[i][0]=make_pair(dep[vis[i]],vis[i]);
		for(int j=1;j<mlog;j++)for(int i=1;i<=k;i++)if(i+(1<<j)-1<=k)
			mn[i][j]=min(mn[i][j-1],mn[i+(1<<j-1)][j-1]);
	}
	int qry(int l,int r){
		if(l>r)swap(l,r);
		int len=lg2[r-l+1];
		return min(mn[l][len],mn[r-(1<<len)+1][len]).second;
	}
}
int dist(int x,int y){
	int z=ST::qry(dfn[x],dfn[y]);
	return dep[x]+dep[y]-2*dep[z];
}

class Diam{
public:
	int u,v,d;
	Diam():u(0),v(0),d(0){}
	Diam(int _u):u(_u),v(_u),d(0){}
	Diam operator+(const Diam &o)const{
		if(u==0)return o;
		if(o.u==0)return *this;
		Diam res=*this;
		if(o.d>res.d)res=o;
		int uu=dist(u,o.u),uv=dist(u,o.v),vu=dist(v,o.u),vv=dist(v,o.v);
		res.d=max(res.d,max(max(uu,uv),max(vu,vv)));
		if(uu==res.d)res.u=u,res.v=o.u;
		else if(uv==res.d)res.u=u,res.v=o.v;
		else if(vu==res.d)res.u=v,res.v=o.u;
		else if(vv==res.d)res.u=v,res.v=o.v;
		return res;
	}
};
class Info{
public:
	Diam val0,val1;
	Info():val0(Diam()),val1(Diam()){}
	Info operator+(const Info &o){
		Info res;
		res.val0=val0+o.val0;
		res.val1=val1+o.val1;
		return res;
	}
};
namespace Segtree{
	bool tag[maxn*4];
	Info t[maxn*4];
	void apply(int cur){
		tag[cur]^=1;
		swap(t[cur].val0,t[cur].val1);
	}
	void pushdown(int cur){
		if(tag[cur]){
			apply(cur<<1);
			apply(cur<<1|1);
			tag[cur]=false;
		}
	}
	void pushup(int cur){
		t[cur]=t[cur<<1]+t[cur<<1|1];
	}
	void build(int cur,int l,int r){
		if(l==r){
			if(tp[pos[l]]==0)t[cur].val0=Diam(pos[l]);
			else t[cur].val1=Diam(pos[l]);
			return;
		}
		int mid=l+r>>1;
		build(cur<<1,l,mid);
		build(cur<<1|1,mid+1,r);
		pushup(cur);
	}
	void update(int cur,int l,int r,int vl,int vr){
		if(l>=vl&&r<=vr){
			apply(cur);
			return;
		}
		pushdown(cur);
		int mid=l+r>>1;
		if(mid>=vl)update(cur<<1,l,mid,vl,vr);
		if(mid<vr)update(cur<<1|1,mid+1,r,vl,vr);
		pushup(cur);
	}
	int query(){
		return max(t[1].val0.d,t[1].val1.d);
	}
}

void dfs(int x,int p,int d,int f){
	dfn[x]=++k;
	vis[k]=x;
	dfnL[x]=++t;
	pos[t]=x;
	dep[x]=d;
	tp[x]=f;
	for(int i=0;i<int(edge[x].size());i++){
		pair<int,int>y=edge[x][i];
		if(y.first==p)continue;
		dfs(y.first,x,d+1,f^w[y.second]);
		ver[y.second]=y.first;
		vis[++k]=x;
	}
	dfnR[x]=t;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++){
		int u,v;
		scanf("%d%d%d",&u,&v,&w[i]);
		edge[u].push_back(make_pair(v,i));
		edge[v].push_back(make_pair(u,i));
	}
	dfs(1,0,0,0);
	ST::init();
	Segtree::build(1,1,n);
	scanf("%d",&q);
	while(q--){
		int e;
		scanf("%d",&e);
		Segtree::update(1,1,n,dfnL[ver[e]],dfnR[ver[e]]);
		printf("%d\n",Segtree::query());
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

namespace io{
	const int size=1<<22|1;
	char iBuf[size],*iS,*iT,c;
	char oBuf[size],*oS=oBuf,*oT=oBuf+size;
	#define getc() (iS==iT?iT=iBuf+fread(iS=iBuf,1,size,stdin),(iS==iT?EOF:(*iS++)):(*iS++))
	template<class T>void qread(T &x){
		int f=1;
		for(c=getc();c<'0'||c>'9';c=getc())
			if(c=='-')f=-1;
		for(x=0;c>='0'&&c<='9';c=getc())
			x=(x<<3)+(x<<1)+(c&15);
		x*=f;
	}
	void flush(){
		fwrite(oBuf,1,oS-oBuf,stdout);
		oS=oBuf;
	}
	void putc(char x){
		*oS++=x;
		if(oS==oT)flush();
	}
	template<class T>void qwrite(T x){
		static char qu[55];
		char *tmp=qu;
		do *tmp++=(x%10)^'0';while(x/=10);
		while(tmp--!=qu)putc(*tmp);
	}
	struct flusher{
		~flusher(){flush();}
	}_;
}

const int maxn=500005;
int n,q,k,t;
int dfn[maxn],vis[maxn*2],dep[maxn],w[maxn],ver[maxn];
int dfnL[maxn],dfnR[maxn],pos[maxn],tp[maxn];
vector<pair<int,int> >edge[maxn];

namespace ST{
	const int mlog=20;
	int lg2[maxn*2];
	pair<int,int>mn[maxn*2][mlog];
	void init(){
		for(int i=2;i<=k;i++)lg2[i]=lg2[i>>1]+1;
		for(int i=1;i<=k;i++)mn[i][0]=make_pair(dep[vis[i]],vis[i]);
		for(int j=1;j<mlog;j++)for(int i=1;i<=k;i++)if(i+(1<<j)-1<=k)
			mn[i][j]=min(mn[i][j-1],mn[i+(1<<j-1)][j-1]);
	}
	int qry(int l,int r){
		if(l>r)swap(l,r);
		int len=lg2[r-l+1];
		return min(mn[l][len],mn[r-(1<<len)+1][len]).second;
	}
}
int dist(int x,int y){
	int z=ST::qry(dfn[x],dfn[y]);
	return dep[x]+dep[y]-2*dep[z];
}

class Diam{
public:
	int u,v,d;
	Diam():u(0),v(0),d(0){}
	Diam(int _u):u(_u),v(_u),d(0){}
	Diam operator+(const Diam &o)const{
		if(u==0)return o;
		if(o.u==0)return *this;
		Diam res=*this;
		if(o.d>res.d)res=o;
		int uu=dist(u,o.u),uv=dist(u,o.v),vu=dist(v,o.u),vv=dist(v,o.v);
		res.d=max(res.d,max(max(uu,uv),max(vu,vv)));
		if(uu==res.d)res.u=u,res.v=o.u;
		else if(uv==res.d)res.u=u,res.v=o.v;
		else if(vu==res.d)res.u=v,res.v=o.u;
		else if(vv==res.d)res.u=v,res.v=o.v;
		return res;
	}
};
class Info{
public:
	Diam val0,val1;
	Info():val0(Diam()),val1(Diam()){}
	Info operator+(const Info &o){
		Info res;
		res.val0=val0+o.val0;
		res.val1=val1+o.val1;
		return res;
	}
};
namespace Segtree{
	bool tag[maxn*4];
	Info t[maxn*4];
	void apply(int cur){
		tag[cur]^=1;
		swap(t[cur].val0,t[cur].val1);
	}
	void pushdown(int cur){
		if(tag[cur]){
			apply(cur<<1);
			apply(cur<<1|1);
			tag[cur]=false;
		}
	}
	void pushup(int cur){
		t[cur]=t[cur<<1]+t[cur<<1|1];
	}
	void build(int cur,int l,int r){
		if(l==r){
			if(tp[pos[l]]==0)t[cur].val0=Diam(pos[l]);
			else t[cur].val1=Diam(pos[l]);
			return;
		}
		int mid=l+r>>1;
		build(cur<<1,l,mid);
		build(cur<<1|1,mid+1,r);
		pushup(cur);
	}
	void update(int cur,int l,int r,int vl,int vr){
		if(l>=vl&&r<=vr){
			apply(cur);
			return;
		}
		pushdown(cur);
		int mid=l+r>>1;
		if(mid>=vl)update(cur<<1,l,mid,vl,vr);
		if(mid<vr)update(cur<<1|1,mid+1,r,vl,vr);
		pushup(cur);
	}
	int query(){
		return max(t[1].val0.d,t[1].val1.d);
	}
}

void dfs(int x,int p,int d,int f){
	dfn[x]=++k;
	vis[k]=x;
	dfnL[x]=++t;
	pos[t]=x;
	dep[x]=d;
	tp[x]=f;
	for(int i=0;i<int(edge[x].size());i++){
		pair<int,int>y=edge[x][i];
		if(y.first==p)continue;
		dfs(y.first,x,d+1,f^w[y.second]);
		ver[y.second]=y.first;
		vis[++k]=x;
	}
	dfnR[x]=t;
}

int main(){
	io::qread(n);
	for(int i=1;i<=n-1;i++){
		int u,v;
		io::qread(u);io::qread(v);io::qread(w[i]);
		edge[u].push_back(make_pair(v,i));
		edge[v].push_back(make_pair(u,i));
	}
	dfs(1,0,0,0);
	ST::init();
	Segtree::build(1,1,n);
	io::qread(q);
	while(q--){
		int e;
		io::qread(e);
		Segtree::update(1,1,n,dfnL[ver[e]],dfnR[ver[e]]);
		io::qwrite(Segtree::query());
		io::putc('\n');
	}
	return 0;
}


/*input
5
1 2 0
1 3 0
3 5 0
3 4 0
5
3
4
1
3
4
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int maxn = 5e5 + 100;
const int mod = 1e9 + 7;
int n, A, B;
vector<pii>adj[maxn];
pii dfs(int v, int p, int d) {
	pii mx = {d, v};
	for (pii to : adj[v]) {
		if (to.x != p) {
			mx = max(mx, dfs(to.x, v, d + 1));
		}
	}
	return mx;
}

int timer;
struct DS {
	int root;
	int tin[maxn], tout[maxn], one[maxn * 4], zero[maxn * 4], lazy[maxn * 4];
	int dep[maxn], value[maxn], to_v[maxn], parent[maxn];

	DS(int rt) {
		memset(parent, 0, sizeof parent);
		memset(dep, 0, sizeof dep);
		memset(lazy, 0, sizeof lazy);

		root = rt;
		timer = 0;
		predfs(root, 0);
		build();
	}

	void predfs(int v, int cur_val) {
		tin[v] = ++timer;
		to_v[tin[v]] = v;
		value[v] = cur_val;
		dep[v] = dep[parent[v]] + 1;

		for (pii to : adj[v]) {
			if (to.x != parent[v]) {
				parent[to.x] = v;
				predfs(to.x, cur_val ^ to.y);
			}
		}

		tout[v] = timer;
	}

	void build(int id = 1, int l = 1, int r = n) {
		if (l == r) {
			if (value[to_v[l]] == 1) {
				one[id] = dep[to_v[l]];
			} else {
				zero[id] = dep[to_v[l]];
			}
			return;
		}
		int mid = (l + r) / 2;
		build(id * 2, l, mid);
		build(id * 2 + 1, mid + 1, r);
		one[id] = max(one[id * 2], one[id * 2 + 1]);
		zero[id] = max(zero[id * 2], zero[id * 2 + 1]);
	}

	int query(int a, int b) {
		if (a == parent[b]) {
			modify(tin[b], tout[b]);
		} else {
			modify(tin[a], tout[a]);
		}

		return zero[1];
	}

	void upd(int id) {
		swap(one[id], zero[id]);
		lazy[id] ^= 1;
	}

	void shift(int id) {
		if (lazy[id]) {
			lazy[id] = 0;
			upd(id * 2);
			upd(id * 2 + 1);
		}
	}

	void modify(int x, int y, int id = 1, int l = 1, int r = n) {
		if (l > y || r < x) {
			return;
		}
		if (l >= x && r <= y) {
			upd(id);
			return;
		}
		shift(id);
		int mid = (l + r) / 2;
		modify(x, y, id * 2, l, mid);
		modify(x, y, id * 2 + 1, mid + 1, r);
		one[id] = max(one[id * 2], one[id * 2 + 1]);
		zero[id] = max(zero[id * 2], zero[id * 2 + 1]);
	}
};
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	vector<pii>edges;
	for (int i = 0; i < n - 1; i++) {
		int a, b, w;
		cin >> a >> b >> w;
		edges.pb({a, b});
		adj[a].pb({b, w});
		adj[b].pb({a, w});
	}

	pii mx = dfs(1, 0, 0);
	A = mx.y;
	B = dfs(A, 0, 0).y;

	DS tree1(A), tree2(B);

	int q;
	cin >> q;
	while (q--) {
		int x;
		cin >> x;
		x--;
		int a, b;
		tie(a, b) = edges[x];

		cout << max(tree1.query(a, b), tree2.query(a, b)) - 1 << "\n";
	}
	return 0;
}


/*input
5
1 2 0
1 3 0
3 5 0
3 4 0
5
3
4
1
3
4
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int maxn = 100;
const int mod = 1e9 + 7;
int n, A, B;
vector<pii>adj[maxn];
pii dfs(int v, int p, int d) {
	pii mx = {d, v};
	for (pii to : adj[v]) {
		if (to.x != p) {
			mx = max(mx, dfs(to.x, v, d + 1));
		}
	}
	return mx;
}

int timer;
struct DS {
	int root;
	int tin[maxn], tout[maxn], one[maxn * 4], zero[maxn * 4], lazy[maxn * 4];
	int dep[maxn], value[maxn], to_v[maxn], parent[maxn];

	DS(int rt) {
		memset(parent, 0, sizeof parent);
		memset(dep, 0, sizeof dep);
		memset(lazy, 0, sizeof lazy);

		root = rt;
		timer = 0;
		predfs(root, 0);
		build();
	}

	void predfs(int v, int cur_val) {
		tin[v] = ++timer;
		to_v[tin[v]] = v;
		value[v] = cur_val;
		dep[v] = dep[parent[v]] + 1;

		for (pii to : adj[v]) {
			if (to.x != parent[v]) {
				parent[to.x] = v;
				predfs(to.x, cur_val ^ to.y);
			}
		}

		tout[v] = timer;
	}

	void build(int id = 1, int l = 1, int r = n) {
		if (l == r) {
			if (value[to_v[l]] == 1) {
				one[id] = dep[to_v[l]];
			} else {
				zero[id] = dep[to_v[l]];
			}
			return;
		}
		int mid = (l + r) / 2;
		build(id * 2, l, mid);
		build(id * 2 + 1, mid + 1, r);
		one[id] = max(one[id * 2], one[id * 2 + 1]);
		zero[id] = max(zero[id * 2], zero[id * 2 + 1]);
	}

	int query(int a, int b) {
		if (a == parent[b]) {
			modify(tin[b], tout[b]);
		} else {
			modify(tin[a], tout[a]);
		}

		return zero[1];
	}

	void upd(int id) {
		swap(one[id], zero[id]);
		lazy[id] ^= 1;
	}

	void shift(int id) {
		if (lazy[id]) {
			lazy[id] = 0;
			upd(id * 2);
			upd(id * 2 + 1);
		}
	}

	void modify(int x, int y, int id = 1, int l = 1, int r = n) {
		if (l > y || r < x) {
			return;
		}
		if (l >= x && r <= y) {
			upd(id);
			return;
		}
		shift(id);
		int mid = (l + r) / 2;
		modify(x, y, id * 2, l, mid);
		modify(x, y, id * 2 + 1, mid + 1, r);
		one[id] = max(one[id * 2], one[id * 2 + 1]);
		zero[id] = max(zero[id * 2], zero[id * 2 + 1]);
	}
};
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	vector<pii>edges;
	for (int i = 0; i < n - 1; i++) {
		int a, b, w;
		cin >> a >> b >> w;
		edges.pb({a, b});
		adj[a].pb({b, w});
		adj[b].pb({a, w});
	}

	pii mx = dfs(1, 0, 0);
	A = mx.y;
	B = dfs(A, 0, 0).y;

	DS tree1(A), tree2(B);

	int q;
	cin >> q;
	while (q--) {
		int x;
		cin >> x;
		x--;
		int a, b;
		tie(a, b) = edges[x];

		cout << max(tree1.query(a, b), tree2.query(a, b)) - 1 << "\n";
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=5e5+5;

const int32_t maxn=N;
template<typename NODE,typename UPDATE>
struct segtree{
	bool built=false,lazy[4*maxn];
	NODE zero=NODE(),t[4*maxn];
	UPDATE noop=UPDATE(),upds[4*maxn];
	int32_t tl[4*maxn],tr[4*maxn];
	inline void pushdown(int32_t v)
	{
		if(lazy[v]){
			apply(v*2,upds[v]);
			apply(v*2+1,upds[v]);
			lazy[v]=0;
			upds[v]=noop;
		}
	}
	inline void apply(int32_t v,UPDATE &val)
	{
		if(tl[v]!=tr[v]){
			lazy[v]=1;
			upds[v].combine(val,tl[v],tr[v]);
		}
		val.apply(t[v],tl[v],tr[v]);
	}
	template<typename T>
	void build(T a, int32_t v, int32_t l, int32_t r) {
		tl[v]=l;
		tr[v]=r;
		if (l == r) {
			t[v]=a[l];
			return;
		} else {
			int32_t tm = (l + r) / 2;
			build(a, v*2, l, tm);
			build(a, v*2+1, tm+1, r);
			t[v].merge(t[v*2],t[v*2+1]);
		}
	}
	NODE query(int32_t v, int l, int r) {
		if (l > tr[v] || r < tl[v])
			return zero;
		if (l <= tl[v] && tr[v] <= r) {
			return t[v];
		}
		pushdown(v);
		NODE a,b,ans;
		a=query(v*2, l, r);
		b=query(v*2+1, l, r);
		ans.merge(a,b);
		return ans;
	}
	void rupd(int32_t v, int l, int r, UPDATE &val)
	{
		if(l > tr[v] || r < tl[v])
			return;
		if(l <= tl[v] && tr[v] <= r)
		{
			apply(v,val);
			return;
		}
		pushdown(v);
		rupd(v*2,l,r,val);
		rupd(v*2+1,l,r,val);
		t[v].merge(t[v*2],t[v*2+1]);
	}
	template<typename T>
	int descent_right(int l, T x, int32_t v, NODE &prev) {
		if (l > tr[v]) // node is completely out of range
			return len;
		if(l <= tl[v]){ // node is completely in range
			NODE cur;
			cur.merge(prev,t[v]);
			if (!cur.check(x)){ // go further right than this node
				swap(prev,cur); // merging this node's contribution
				return len;
			}
			if (tl[v]==tr[v]) {
				return tr[v];
			}
		}
		pushdown(v);
		int ans=descent_right(l, x, v*2, prev); // trying to find in left child
		if(ans!=len)return ans; // found in left child
		return descent_right(l, x, v*2+1, prev); // finding in right child
	}
	template<typename T>
	int descent_left(int r, T x, int32_t v, NODE &prev) {
		if (r < tl[v]) // node is completely out of range
			return -1;
		if(r >= tr[v]){ // node is completely in range
			NODE cur;
			cur.merge(t[v],prev);
			if (!cur.check(x)){ // go further left than this node
				swap(cur,prev); // merging this node's contribution
				return -1;
			}
			if (tl[v]==tr[v]) {
				return tl[v];
			}
		}
		pushdown(v);
		int ans=descent_left(r, x, v*2+1, prev); // trying to find in right child
		if(ans!=-1)return ans; // found in right child
		return descent_left(r, x, v*2, prev); // finding in left child
	}

	int len=maxn;
	void clear(){
		fill(t,t+4*len,zero);
		fill(lazy,lazy+4*len,false);
		fill(upds,upds+4*len,noop);
	}
	template<typename T>
	void build(T a){
		build(a,1,0,len-1);
		built=true;
	}
	template<typename T>
	int descent_right(int l, T x){ // minimum r such that [l...r].check(x) == true, returns segtree.len if not found
		NODE prev=zero;
		return descent_right(l,x,1,prev);
	}
	template<typename T>
	int descent_left(int r, T x){ // maximum l such that [l...r].check(x) == true, returns -1 if not found
		NODE prev=zero;
		return descent_left(r,x,1,prev);
	}
	NODE query(int l,int r){
		if(!built)build(t);
		return query(1,l,r);
	}
	void rupd(int l,int r,UPDATE val){
		if(!built)build(t);
		rupd(1,l,r,val);
	}
};

#define node node1
#define update update1
struct node{
	int e = 0, o = 0;
	node(){}
	node(int val){
		e = val;
	}
	void merge(node &l,node &r)
	{
		e = max(l.e,r.e);
		o = max(l.o,r.o);
	}
	bool check(int x){
		return false;
	}
};
struct update{
	int v = 0;
	update(){}
	update(int val){
		v = val;
	}
	void combine(update &other,int32_t tl,int32_t tr){
		v ^= other.v;
	}
	void apply(node &x,int32_t tl,int32_t tr){
		if(v){
			swap(x.e,x.o);
		}
	}
};
segtree<node,update> t;
#undef node
#undef update

// ------------------

int n,m;
pii edgs[N];
vector<int> f,q;

int tim;
int st[N],et[N],dep[N],ev[N];
vector<pii> v[N];
void dfs(int z,int p = 0,int d = 0){
	st[z] = tim++;
	dep[st[z]] = d;
	for(pii x:v[z]){
		if(x.fr==p)continue;
		ev[x.sc] = x.fr;
		dfs(x.fr,z,d+1);
	}
	et[z] = tim - 1;
}

pii auxdfs(int z,int p = 0,int d = 0){
	pii ret = {d,z};
	for(pii x:v[z]){
		if(x.fr==p)continue;
		pii tmp = auxdfs(x.fr,z,d+1);
		amax(ret,tmp);
	}
	return ret;
}

int ans[N];

void solve(){
	cin >> n;

	rep(i,1,n){
		int x,y,z;
		cin >> x >> y >> z;
		edgs[i] = {x,y};
		v[x].pb({y,i});
		v[y].pb({x,i});
		if(z) f.pb(i);
	}

	cin >> m;
	rep(i,0,m){
		int x;
		cin >> x;
		q.pb(x);
	}

	int root = 1;
	rep(zz,0,2){
		root = auxdfs(root).sc;
		tim = 0;
		dfs(root);
		t.clear();
		t.build(dep);
		for(int x:f){
			int y = ev[x];
			t.rupd(st[y],et[y],1);
		}
		rep(i,0,m){
			int x = q[i];
			int y = ev[x];
			t.rupd(st[y],et[y],1);
			amax(ans[i],t.query(st[root],et[root]).e);
		}

	}

	rep(i,0,m){
		cout << ans[i] << "\n";
	}

}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int sz=5e5+10;
int rt[2], di=0;
struct re
{
    int to, i, w;
};
vector <re> sv[sz];
pair <int, int> dfs(int v, int pr)
{
    pair <int, int> be = {0, v};
    for(int a=0; a<sv[v].size(); a++)
    {
        int ne=sv[v][a].to;
        if(ne!=pr)
        {
            pair <int, int> re=dfs(ne, v);
            if(be.first+re.first>di)
            {
                di=be.first+re.first, rt[0]=be.second, rt[1]=re.second;
            }
            be=max(be, re);
        }
    }
    be.first++;
    return be;
}

int L[2][sz], R[2][sz], c[2][sz], h[2][sz], timer;
int dfs2(int i, int v, int pr)
{
    int p=timer++;
    L[i][pr]=p;
    R[i][pr]=p;
    for(int a=0; a<sv[v].size(); a++)
    {
        int ne=sv[v][a].to, nu=sv[v][a].i, w=sv[v][a].w;
        if(nu!=pr)
        {
            c[i][timer]=c[i][p]^w;
            h[i][timer]=h[i][p]+1;
            R[i][pr]+=dfs2(i, ne, nu);
        }
    }
    return R[i][pr]-p+1;
}

struct el
{
    bool add=0;
    int ma[2]={0, 0};
};
el dot[2][sz*4];

void push(int i, int nu)
{
    dot[i][nu*2].add^=dot[i][nu].add;
    dot[i][nu*2+1].add^=dot[i][nu].add;
    dot[i][nu].add=0;
}
void recalc(int i, int nu)
{
    for(int j=0; j<2; j++)
    {
        dot[i][nu].ma[j]=max(dot[i][nu*2].ma[j^dot[i][nu*2].add], dot[i][nu*2+1].ma[j^dot[i][nu*2+1].add]);
    }
}
void build(int i, int nu, int l, int r)
{
    if(l==r)
    {
        dot[i][nu].ma[c[i][l]]=h[i][l];
    }
    else
    {
        int mid=(l+r)>>1;
        build(i, nu*2, l, mid);
        build(i, nu*2+1, mid+1, r);
        recalc(i, nu);
    }
}
int lg, rg;
void cha(int i, int nu, int l, int r)
{
    if(l>=lg and r<=rg) dot[i][nu].add^=1;
    else if(!(l>rg or r<lg))
    {
        int mid=(l+r)>>1;
        push(i, nu);
        cha(i, nu*2, l, mid);
        cha(i, nu*2+1, mid+1, r);
        recalc(i, nu);
    }
}
main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin>>n;
    for(int a=1; a<n; a++)
    {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        u--, v--;
        sv[v].push_back({u, a, w});
        sv[u].push_back({v, a, w});
    }
    dfs(0, 0);
    for(int i=0; i<2; i++)
    {
        timer=0;
        dfs2(i, rt[i], 0);
        build(i, 1, 0, n-1);
    }
    int q;
    cin>>q;
    for(int a=0; a<q; a++)
    {
        int nu, an=0;
        scanf("%d", &nu);
        for(int i=0; i<2; i++)
        {
            lg=L[i][nu], rg=R[i][nu];
            cha(i, 1, 0, n-1);
            an=max(an, dot[i][1].ma[0]);
        }
        printf("%d\n", an);
    }
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 5e5 + 5;

int N, tin[maxn], tout[maxn], depth[maxn];
vector<ii> adj[maxn];
int change[maxn];
int U[maxn], V[maxn];
int res[maxn];
int Q;
ar<int, 2> tr[4 * maxn];
int lazy[4 * maxn];
int nTime = 0;
int pos[maxn];
int stone[maxn];

void prep(int u, int p = -1) {
  tin[u] = ++nTime;
  pos[nTime] = u;
  for (auto & v : adj[u]) {
    if (v.fi != p) {
      stone[v.fi] = stone[u] + v.se;
      depth[v.fi] = depth[u] + 1;
      prep(v.fi, u);
    }
  }
  tout[u] = nTime;
}

#define lc id << 1
#define rc id << 1 | 1
void apply(int id, int l, int r) {
  if (!lazy[id]) return;
  swap(tr[id][0], tr[id][1]);
  if (l != r) {
    lazy[lc] ^= lazy[id];
    lazy[rc] ^= lazy[id];
  }
  lazy[id] = 0;
}

void add(int id) {
  for (int i = 0; i < 2; ++i)
    tr[id][i] = max(tr[lc][i], tr[rc][i]);
}

void build(int id, int l, int r) {
  lazy[id] = 0;
  if (l == r) {
    tr[id][0] = tr[id][1] = 0;
    tr[id][stone[pos[l]] % 2] = depth[pos[l]];
    return;
  }
  int mid = (l + r) / 2;
  build(lc, l, mid); build(rc, mid + 1, r);
  add(id);
}

void flip(int L, int R, int id = 1, int l = 1, int r = N) {
  apply(id, l, r);
  if (R < l || r < L)
    return;
  if (L <= l && r <= R) {
    lazy[id] ^= 1;
    apply(id, l, r);
    return;
  }
  int mid = (l + r) / 2;
  flip(L, R, lc, l, mid); flip(L, R, rc, mid + 1, r);
  add(id);
}

void solve(int root) {
  nTime = 0; stone[root] = depth[root] = 0;
  prep(root);
  build(1, 1, N);

  for (int i = 1; i <= Q; ++i) {
    int id = change[i];
    int u = U[id], v = V[id];
    if (depth[u] < depth[v]) swap(u, v);
    flip(tin[u], tout[u]);
    apply(1, 1, N);
    res[i] = max(res[i], tr[1][0]);
  }
}

signed main(void) {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
  freopen("A.INP", "r", stdin);
  freopen("A.OUT", "w", stdout);
#endif // LOCAL
  cin >> N;
  for (int i = 1; i < N; ++i) {
    int u, v, c; cin >> u >> v >> c;
    adj[u].eb(v, c); adj[v].eb(u, c);
    U[i] = u; V[i] = v;
    //cerr << u << ' ' << v << '\n';
  }
  cin >> Q;
  for (int i = 1; i <= Q; ++i) {
    cin >> change[i];
  }

  //for (auto & it : adj[1]) cerr << it.fi << ' ';

  function<void(int, int)> dfs = [&](int u, int p) {
    for (auto & v : adj[u]) {
      if (v.fi != p) {
        depth[v.fi] = depth[u] + 1;
        dfs(v.fi, u);
      }
    }
  };
  int r1, r2;
  auto Diamater = [&](void) {
    depth[1] = 0;
    dfs(1, -1);
    r1 = -1;
    for (int i = 1; i <= N; ++i) {
      if (r1 == -1 || depth[i] > depth[r1])
        r1 = i;
    }
    depth[r1] = 0;
    dfs(r1, -1);
    r2 = -1;
    for (int i = 1; i <= N; ++i) {
      if (r2 == -1 || depth[i] > depth[r2]) {
        r2 = i;
      }
    }

  };
  Diamater();

  solve(r1); solve(r2);
  for (int i = 1; i <= Q; ++i)
    cout << res[i] << '\n';
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxN=500005;

int N,Q;
int lnk[maxN];
int pre[maxN<<1],tgt[maxN<<1],cnt;int val[maxN<<1];
int pos[maxN];
void add_E(int u,int v,int c){
	pre[++cnt]=lnk[u],tgt[cnt]=v,val[cnt]=c,lnk[u]=cnt;
}

int dep[maxN],wdep[maxN];
int Tin[maxN],Tout[maxN];
int dfn[maxN<<1],idx;
void dfs(int x,int f){
	dfn[++idx]=x;Tin[x]=idx;
	for(int e=lnk[x];e;e=pre[e])if(tgt[e]!=f)
		pos[(e+1)>>1]=tgt[e],dep[tgt[e]]=dep[x]+1,wdep[tgt[e]]=wdep[x]+val[e],dfs(tgt[e],x),dfn[++idx]=x;
	Tout[x]=idx;
}

int W[maxN<<3][2],M[maxN<<3],LM[maxN<<3][2],MR[maxN<<3][2],LMR[maxN<<3][2],Lzy[maxN<<3];
void push_up(int x){
	M[x]=max(M[x<<1],M[x<<1|1]);
	for(int k=0;k<2;k++){
		W[x][k]=max(W[x<<1][k],W[x<<1|1][k]);
		LM[x][k]=max(LM[x<<1][k],LM[x<<1|1][k]);
		MR[x][k]=max(MR[x<<1][k],MR[x<<1|1][k]);
		LMR[x][k]=max(LMR[x<<1][k],LMR[x<<1|1][k]);
		LM[x][k]=max(LM[x][k],W[x<<1][k]+M[x<<1|1]);
		MR[x][k]=max(MR[x][k],M[x<<1]+W[x<<1|1][k]);
	}
	for(int k1=0;k1<2;k1++)
	for(int k2=0;k2<2;k2++)
		LMR[x][k1^k2]=max(LMR[x][k1^k2],max(LM[x<<1][k1]+W[x<<1|1][k2],W[x<<1][k1]+MR[x<<1|1][k2]));
}
void Rev(int x){
	swap(W[x][0],W[x][1]);
	swap(LM[x][0],LM[x][1]);
	swap(MR[x][0],MR[x][1]);
	Lzy[x]^=1;
}
void push_down(int x){if(!Lzy[x]) return;Rev(x<<1);Rev(x<<1|1);Lzy[x]=0;}
void Build(int x,int l,int r){
	if(l==r){
		int k=wdep[dfn[l]]&1;
		W[x][k]=dep[dfn[l]];M[x]=-2*dep[dfn[l]];
		LM[x][k]=MR[x][k]=-dep[dfn[l]];
		W[x][k^1]=-0x3f3f3f3f;
		LM[x][k^1]=MR[x][k^1]=-0x3f3f3f3f;
		return;
	}
	int mid=(l+r)>>1;
	Build(x<<1,l,mid);Build(x<<1|1,mid+1,r);
	push_up(x);
}
void Update(int x,int l,int r,int L,int R){
	if(L<=l&&r<=R){Rev(x);return;}
	int mid=(l+r)>>1;
	push_down(x);
	if(L<=mid) Update(x<<1,l,mid,L,R);
	if(R>mid) Update(x<<1|1,mid+1,r,L,R);
	push_up(x);
}

int main(){
	scanf("%d",&N);
	for(int i=1;i<N;i++){
		int u,v,c;scanf("%d%d%d",&u,&v,&c);
		add_E(u,v,c);add_E(v,u,c);
	}
	dfs(1,0);
	Build(1,1,idx);
	scanf("%d",&Q);
	while(Q--){
		int d;scanf("%d",&d);
		Update(1,1,idx,Tin[pos[d]],Tout[pos[d]]);
		printf("%d\n",LMR[1][0]);
	}
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxN=500005;

int N,Q;
int lnk[maxN];
int pre[maxN<<1],tgt[maxN<<1],cnt;int val[maxN<<1];
int pos[maxN];
void add_E(int u,int v,int c){
	pre[++cnt]=lnk[u],tgt[cnt]=v,val[cnt]=c,lnk[u]=cnt;
}

int dep[maxN],wdep[maxN];
int Tin[maxN],Tout[maxN];
int dfn[maxN<<1],idx;
void dfs(int x,int f){
	dfn[++idx]=x;Tin[x]=idx;
	for(int e=lnk[x];e;e=pre[e])if(tgt[e]!=f)
		pos[(e+1)>>1]=tgt[e],dep[tgt[e]]=dep[x]+1,wdep[tgt[e]]=wdep[x]+val[e],dfs(tgt[e],x),dfn[++idx]=x;
	Tout[x]=idx;
}

int W[maxN<<8][2],M[maxN<<8],LM[maxN<<8][2],MR[maxN<<8][2],LMR[maxN<<8][2],Lzy[maxN<<8];
void push_up(int x){
	M[x]=max(M[x<<1],M[x<<1|1]);
	for(int k=0;k<2;k++){
		W[x][k]=max(W[x<<1][k],W[x<<1|1][k]);
		LM[x][k]=max(LM[x<<1][k],LM[x<<1|1][k]);
		MR[x][k]=max(MR[x<<1][k],MR[x<<1|1][k]);
		LMR[x][k]=max(LMR[x<<1][k],LMR[x<<1|1][k]);
		LM[x][k]=max(LM[x][k],W[x<<1][k]+M[x<<1|1]);
		MR[x][k]=max(MR[x][k],M[x<<1]+W[x<<1|1][k]);
	}
	for(int k1=0;k1<2;k1++)
	for(int k2=0;k2<2;k2++)
		LMR[x][k1^k2]=max(LMR[x][k1^k2],max(LM[x<<1][k1]+W[x<<1|1][k2],W[x<<1][k1]+MR[x<<1|1][k2]));
}
void Rev(int x){
	swap(W[x][0],W[x][1]);
	swap(LM[x][0],LM[x][1]);
	swap(MR[x][0],MR[x][1]);
	Lzy[x]^=1;
}
void push_down(int x){if(!Lzy[x]) return;Rev(x<<1);Rev(x<<1|1);Lzy[x]=0;}
void Build(int x,int l,int r){
	if(l==r){
		int k=wdep[dfn[l]]&1;
		W[x][k]=dep[dfn[l]];M[x]=-2*dep[dfn[l]];
		LM[x][k]=MR[x][k]=-dep[dfn[l]];
		W[x][k^1]=-0x3f3f3f3f;
		LM[x][k^1]=MR[x][k^1]=-0x3f3f3f3f;
		return;
	}
	int mid=(l+r)>>1;
	Build(x<<1,l,mid);Build(x<<1|1,mid+1,r);
	push_up(x);
}
void Update(int x,int l,int r,int L,int R){
	if(L<=l&&r<=R){Rev(x);return;}
	int mid=(l+r)>>1;
	push_down(x);
	if(L<=mid) Update(x<<1,l,mid,L,R);
	if(R>mid) Update(x<<1|1,mid+1,r,L,R);
	push_up(x);
}

int main(){
	scanf("%d",&N);
	for(int i=1;i<N;i++){
		int u,v,c;scanf("%d%d%d",&u,&v,&c);
		add_E(u,v,c);add_E(v,u,c);
	}
	dfs(1,0);
	Build(1,1,idx);
	scanf("%d",&Q);
	while(Q--){
		int d;scanf("%d",&d);
		Update(1,1,idx,Tin[pos[d]],Tout[pos[d]]);
		printf("%d\n",LMR[1][0]);
	}
}


#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define lun(x) (int)x.size()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<60);
const int inf=(1<<30);
const int nmax=5e5+50;
const ll mod=1e9+7;
using namespace std;
int n,x,y,t,tt,ts,in[nmax],out[nmax],nd[nmax],pr[nmax],ds[nmax],bl,mx,lzy[4*nmax],fe,se,rs[nmax],i,ex[nmax],ey[nmax],m,q[nmax];
pair<int,int>st[4*nmax];
vector<pair<int,int> >g[nmax];
void fnd(int x,int p,int d)
{
    if(d>mx)
    {
        mx=d;
        if(!bl)fe=x;
        else se=x;
    }
    for(int i=0;i<lun(g[x]);i++)if(g[x][i].fr!=p)fnd(g[x][i].fr,x,d+1);
}
void dfs(int x,int p,int c)
{
    ds[x]=pr[x]=0;
    if(x!=p)
    {
        pr[x]=pr[p]^c;
        ds[x]=ds[p]+1;
    }
    in[x]=++tt;
    nd[tt]=x;
    for(int i=0;i<lun(g[x]);i++)if(g[x][i].fr!=p)dfs(g[x][i].fr,x,g[x][i].sc);
    out[x]=tt;
}
pair<int,int> mrg(pair<int,int> x,pair<int,int> y)
{
    return mkp(max(x.fr,y.fr),max(x.sc,y.sc));
}
void build(int x,int l,int r)
{
    if(l==r)
    {
        st[x]=mkp(0,0);
        if(pr[nd[l]])st[x].sc=ds[nd[l]];
        else st[x].fr=ds[nd[l]];
        return;
    }
    int mid=(l+r)/2;
    build(2*x,l,mid);
    build(2*x+1,mid+1,r);
    st[x]=mrg(st[2*x],st[2*x+1]);
}
void push(int nod,int l,int r)
{
    if(!lzy[nod])return;
    swap(st[nod].fr,st[nod].sc);
    if(l!=r)
    {
    	lzy[nod*2]^=lzy[nod];
		lzy[nod*2+1]^=lzy[nod];
	}
    lzy[nod]=0;
}
void upd(int nod,int l,int r,int tl,int tr)
{
    push(nod,l,r);
    if(tl<=l && r<=tr)
	{
        lzy[nod]^=1;
        push(nod,l,r);
        return;
    }
    int mid=(l+r)/2;
    if(tl<=mid)upd(nod*2,l,mid,tl,tr);
    if(mid<tr)upd(nod*2+1,mid+1,r,tl,tr);
    push(nod*2,l,mid);
	push(nod*2+1,mid+1,r);
    st[nod]=mrg(st[nod*2],st[nod*2+1]);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<n;i++)
    {
        cin>>x>>y>>t;
        ex[i]=x,ey[i]=y;
        g[x].pb(mkp(y,t));
        g[y].pb(mkp(x,t));
    }
    cin>>m;
    for(i=1;i<=m;i++)cin>>q[i];
    fnd(1,1,0);
    mx=0,bl=1;
    fnd(fe,fe,0);
    for(ts=0;ts<2;ts++)
    {
        tt=0;
        for(i=1;i<=4*n;i++)lzy[i]=0;
        dfs(fe,fe,0);
        build(1,1,n);
        for(i=1;i<=m;i++)
        {
            x=ex[q[i]];
            if(in[ex[q[i]]]<in[ey[q[i]]])x=ey[q[i]];
            upd(1,1,n,in[x],out[x]);
            push(1,1,n);
            rs[i]=max(rs[i],st[1].fr);
        }
        swap(fe,se);
    }
    for(i=1;i<=m;i++)cout<<rs[i]<<'\n';
	return 0;
}


#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define lun(x) (int)x.size()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<60);
const int inf=(1<<30);
const int nmax=5e5+50;
const ll mod=1e9+7;
using namespace std;
int n,x,y,t,tt,ts,in[nmax],out[nmax],nd[nmax],pr[nmax],ds[nmax],bl,mx,lzy[4*nmax],fe,se,rs[nmax],i,ex[nmax],ey[nmax],m,q[nmax];
pair<int,int>st[4*nmax];
vector<pair<int,int> >g[nmax];
void fnd(int x,int p,int d)
{
    if(d>mx)
    {
        mx=d;
        if(!bl)fe=x;
        else se=x;
    }
    for(int i=0;i<lun(g[x]);i++)if(g[x][i].fr!=p)fnd(g[x][i].fr,x,d+1);
}
void dfs(int x,int p,int c)
{
    ds[x]=pr[x]=0;
    if(x!=p)
    {
        pr[x]=pr[p]^c;
        ds[x]=ds[p]+1;
    }
    in[x]=++tt;
    nd[tt]=x;
    for(int i=0;i<lun(g[x]);i++)if(g[x][i].fr!=p)dfs(g[x][i].fr,x,g[x][i].sc);
    out[x]=tt;
}
pair<int,int> mrg(pair<int,int> x,pair<int,int> y)
{
    return mkp(max(x.fr,y.fr),max(x.sc,y.sc));
}
void build(int x,int l,int r)
{
    if(l==r)
    {
        st[x]=mkp(0,0);
        if(pr[nd[l]])st[x].sc=ds[nd[l]];
        else st[x].fr=ds[nd[l]];
        return;
    }
    int mid=(l+r)/2;
    build(2*x,l,mid);
    build(2*x+1,mid+1,r);
    st[x]=mrg(st[2*x],st[2*x+1]);
}
void push(int nod,int l,int r)
{
    if(!lzy[nod])return;
    swap(st[nod].fr,st[nod].sc);
    if(l!=r)
    {
    	lzy[nod*2]^=lzy[nod];
		lzy[nod*2+1]^=lzy[nod];
	}
    lzy[nod]=0;
}
void upd(int nod,int l,int r,int tl,int tr)
{
    push(nod,l,r);
    if(tl<=l && r<=tr)
	{
        lzy[nod]^=1;
        push(nod,l,r);
        return;
    }
    int mid=(l+r)/2;
    if(tl<=mid)upd(nod*2,l,mid,tl,tr);
    if(mid<tr)upd(nod*2+1,mid+1,r,tl,tr);
    push(nod*2,l,mid);
	push(nod*2+1,mid+1,r);
    st[nod]=mrg(st[nod*2],st[nod*2+1]);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<n;i++)
    {
        cin>>x>>y>>t;
        ex[i]=x,ey[i]=y;
        g[x].pb(mkp(y,t));
        g[y].pb(mkp(x,t));
    }
    cin>>m;
    for(i=1;i<=m;i++)cin>>q[i];
    fnd(1,1,0);
    mx=0,bl=1;
    fnd(fe,fe,0);
    for(ts=0;ts<2;ts++)
    {
        tt=0;
        dfs(fe,fe,0);
        build(1,1,n);
        for(i=1;i<=m;i++)
        {
            x=ex[q[i]];
            if(in[ex[q[i]]]<in[ey[q[i]]])x=ey[q[i]];
            upd(1,1,n,in[x],out[x]);
            push(1,1,n);
            rs[i]=max(rs[i],st[1].fr);
        }
        swap(fe,se);
    }
    for(i=1;i<=m;i++)cout<<rs[i]<<'\n';
	return 0;
}


#include<bits/stdc++.h>
#define Accepted 0
using namespace std;
const int maxn=1e6;
int n,x[555555],y[555555],t[555555],cnt,beg[555555],en[555555],dep[555555],crt,vl[555555],b[555555],e[555555],id,Log[1111111],ww[555555],q;
struct treenode
{
	int lazy,x0,y0,x1,y1,mx0,mx1;
	treenode()
	{
		x0=y0=x1=y1=-1;
		mx0=mx1=-1e9;
		lazy=0;
	}
}tree[2222222];
vector<pair<int,int> > g[555555];
int arr[1111111],st[22][1111111];
void dfs(int i,int fa)
{
	dep[i]=dep[fa]+1;
	beg[i]=++cnt;
	for (int j=0;j<g[i].size();j++)
	{
		int to=g[i][j].first,val=g[i][j].second;
		if (to==fa) continue;
		vl[to]=vl[i]^val;
		dfs(to,i);
	}
	en[i]=cnt;
}
void rfs(int i,int fa)
{
	++crt;b[i]=crt;
	arr[crt]=dep[i];
	for (int j=0;j<g[i].size();j++)
	{
		int to=g[i][j].first;
		if (to==fa) continue;
		rfs(to,i);
		++crt;arr[crt]=dep[i];
	}
	e[i]=crt;
}
int get(int l,int r)
{
	int x=Log[r-l+1];
	return min(st[x][l],st[x][r-(1<<x)+1]);
}
int dist(int x,int y)
{
	if (x==-1 || y==-1) return -1e9;
	if (b[x]>b[y]) swap(x,y);
	return dep[x]+dep[y]-(get(b[x],e[y])<<1);
}
void pushup(int node)
{
	int mx=-2e9,cr;
	if (tree[node<<1].mx0>mx)
	{
		mx=tree[node<<1].mx0;
		tree[node].x0=tree[node<<1].x0;tree[node].y0=tree[node<<1].y0;
	}
	if (tree[(node<<1)|1].mx0>mx)
	{
		mx=tree[(node<<1)|1].mx0;
		tree[node].x0=tree[(node<<1)|1].x0;tree[node].y0=tree[(node<<1)|1].y0;
	}
	cr=dist(tree[node<<1].x0,tree[(node<<1)|1].x0);
	if (cr>mx)
	{
		mx=cr;
		tree[node].x0=tree[node<<1].x0;tree[node].y0=tree[(node<<1)|1].x0;
	}
	cr=dist(tree[node<<1].x0,tree[(node<<1)|1].y0);
	if (cr>mx)
	{
		mx=cr;
		tree[node].x0=tree[node<<1].x0;tree[node].y0=tree[(node<<1)|1].y0;
	}
	cr=dist(tree[node<<1].y0,tree[(node<<1)|1].x0);
	if (cr>mx)
	{
		mx=cr;
		tree[node].x0=tree[node<<1].y0;tree[node].y0=tree[(node<<1)|1].x0;
	}
	cr=dist(tree[node<<1].y0,tree[(node<<1)|1].y0);
	if (cr>mx)
	{
		mx=cr;
		tree[node].x0=tree[node<<1].y0;tree[node].y0=tree[(node<<1)|1].y0;
	}
	tree[node].mx0=mx;
	mx=-2e9;
	if (tree[node<<1].mx1>mx)
	{
		mx=tree[node<<1].mx1;
		tree[node].x1=tree[node<<1].x1;tree[node].y1=tree[node<<1].y1;
	}
	if (tree[(node<<1)|1].mx1>mx)
	{
		mx=tree[(node<<1)|1].mx1;
		tree[node].x1=tree[(node<<1)|1].x1;tree[node].y1=tree[(node<<1)|1].y1;
	}
	cr=dist(tree[node<<1].x1,tree[(node<<1)|1].x1);
	if (cr>mx)
	{
		mx=cr;
		tree[node].x1=tree[node<<1].x1;tree[node].y1=tree[(node<<1)|1].x1;
	}
	cr=dist(tree[node<<1].x1,tree[(node<<1)|1].y1);
	if (cr>mx)
	{
		mx=cr;
		tree[node].x1=tree[node<<1].x1;tree[node].y1=tree[(node<<1)|1].y1;
	}
	cr=dist(tree[node<<1].y1,tree[(node<<1)|1].x1);
	if (cr>mx)
	{
		mx=cr;
		tree[node].x1=tree[node<<1].y1;tree[node].y1=tree[(node<<1)|1].x1;
	}
	cr=dist(tree[node<<1].y1,tree[(node<<1)|1].y1);
	if (cr>mx)
	{
		mx=cr;
		tree[node].x1=tree[node<<1].y1;tree[node].y1=tree[(node<<1)|1].y1;
	}
	tree[node].mx1=mx;
}
void push(int node)
{
	tree[node].lazy^=1;
	swap(tree[node].x0,tree[node].x1);
	swap(tree[node].y0,tree[node].y1);
	swap(tree[node].mx0,tree[node].mx1);
}
void pushdown(int node)
{
	if (tree[node].lazy)
	{
		push(node<<1);
		push((node<<1)|1);
		tree[node].lazy=0;
	}
}
void build(int l,int r,int node)
{
	if (l==r)
	{
		if (vl[ww[l]]==1)
		{
			tree[node].x0=tree[node].y0=ww[l];
			tree[node].x1=tree[node].y1=-1;
			tree[node].mx0=0;tree[node].mx1=-1e9;
		}
		else
		{
			tree[node].x1=tree[node].y1=ww[l];
			tree[node].x0=tree[node].y0=-1;
			tree[node].mx0=-1e9;tree[node].mx1=0;
		}
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,node<<1);
	build(mid+1,r,(node<<1)|1);
	pushup(node);
}
void update(int beg,int en,int l,int r,int node)
{
	if (l>en || r<beg) return;
	if (l>=beg && r<=en)
	{
		push(node);
		return;
	}
	int mid=(l+r)>>1;
	pushdown(node);
	update(beg,en,l,mid,node<<1);
	update(beg,en,mid+1,r,(node<<1)|1);
	pushup(node);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		scanf("%d%d%d",&x[i],&y[i],&t[i]);
		g[x[i]].push_back(make_pair(y[i],t[i]));
		g[y[i]].push_back(make_pair(x[i],t[i]));
	}
	dfs(1,0);
	rfs(1,0);
	for (int i=2;i<=maxn;i++) Log[i]=Log[i>>1]+1;
	for (int i=1;i<=crt;i++) st[0][i]=arr[i];
	for (int i=1;i<=20;i++)
	{
		for (int j=1;j<=crt;j++)
		{
			st[i][j]=st[i-1][j];
			if (j+(1<<(i-1))<=crt) st[i][j]=min(st[i][j],st[i-1][j+(1<<(i-1))]);
		}
	}
	for (int i=1;i<=n;i++) ww[beg[i]]=i;
	build(1,n,1);
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d",&id);
		if (dep[x[id]]<dep[y[id]]) swap(x[id],y[id]);
		update(beg[x[id]],en[x[id]],1,n,1);
		printf("%d\n",max(tree[1].mx0,tree[1].mx1));
	}
	return Accepted;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
#define Maxn 500010
int ty[Maxn];
int head[Maxn],v[Maxn<<1],w[Maxn<<1],nxt[Maxn<<1],tot=0;
inline void add_edge(int s,int e,int t){
	tot++;v[tot]=e;w[tot]=t;nxt[tot]=head[s];head[s]=tot;
	tot++;v[tot]=s;w[tot]=t;nxt[tot]=head[e];head[e]=tot;
}

int S,T;
int fuck[Maxn];
void search(int u,int f,int &node){//remember to initial
	if(fuck[u]>fuck[node])node=u;
	for(int i=head[u];i;i=nxt[i])
		if(v[i]^f){
			fuck[v[i]]=fuck[u]+1;
			search(v[i],u,node);
		}
}

struct Tree{
	int depth[Maxn],dis[Maxn],seq[Maxn],in[Maxn],dfk=0;
	int L[Maxn],R[Maxn];
	void dfs(int u,int f){
		dfk++;in[u]=dfk;seq[dfk]=u;
		for(int i=head[u];i;i=nxt[i])
			if(v[i]^f){
				dis[v[i]]=dis[u]+1;
				depth[v[i]]=depth[u]^ty[w[i]];
				dfs(v[i],u);
				L[w[i]]=in[v[i]];R[w[i]]=dfk;
			}
	}
	int dist[Maxn<<2][2],tag[Maxn<<2];
	void make_tag(int k){
		tag[k]^=1;
		swap(dist[k][0],dist[k][1]);
	}
	void push_up(int k){
		for(int i=0;i<2;++i)dist[k][i]=max(dist[k<<1][i],dist[k<<1|1][i]);
	}
	void push_down(int k){
		if(tag[k]){
			make_tag(k<<1);
			make_tag(k<<1|1);
			tag[k]=0;
		}
	}
	void Build_Tree(int k,int l,int r){
		if(l==r){
			int u=seq[l];
			dist[k][depth[u]]=dis[u];
			dist[k][depth[u]^1]=-1;
			return;
		}
		int mid=(l+r)>>1;
		Build_Tree(k<<1,l,mid);
		Build_Tree(k<<1|1,mid+1,r);
		push_up(k);
	}
	void Modify(int k,int l,int r,int L,int R){
		if(l==L&&r==R){
			make_tag(k);
			return;
		}
		push_down(k);
		int mid=(l+r)>>1;
		if(R<=mid)Modify(k<<1,l,mid,L,R);
		else if(mid<L)Modify(k<<1|1,mid+1,r,L,R);
		else{
			Modify(k<<1,l,mid,L,mid);
			Modify(k<<1|1,mid+1,r,mid+1,R);
		}
		push_up(k);
	}
	void mo(int ed){Modify(1,1,n,L[ed],R[ed]);}
	int query(){return dist[1][0];}
}T1,T2;

inline void rd(int &x){
	x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
}

char st[10];int tp;
void print(int x){
	if(!x)putchar('0');
	else{
		while(x){
			st[++tp]=x%10+'0';
			x/=10;
		}
		while(tp)putchar(st[tp--]);
	}
}

int main(){
	rd(n);
	int s,e,t;
	for(int i=1;i<n;++i){
		rd(s);rd(e);rd(t);
		ty[i]=t;
		add_edge(s,e,i);
	}
	rd(m);
	S=1;search(1,0,S);
	T=S;fuck[T]=0;search(S,0,T);
	T1.dfs(S,0);T1.Build_Tree(1,1,n);
	T2.dfs(T,0);T2.Build_Tree(1,1,n);
	int ed;
	while(m--){
		rd(ed);
		T1.mo(ed);T2.mo(ed);
		int res=max(T1.query(),T2.query());
		print(res);puts("");
	}
	return 0;
}