#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef double ld;

const double eps = 1e-8;
const ll INF64 = 1e18;
const double INF = 2e9 + 63;
const ll mod = 1e9 + 7;
const int maxn = 3e3 + 79;
const ll sigma = 27;
const double pi =acos(-1);

struct VertVal {
    ll lowest0;
    ll lowest1;
};

template <typename T, typename PushT>
struct RMQ {
    vector<T> mas;
    T neutral;
    int size;
    std::function<T(const T&,const T&)> op;

    vector<PushT> masPush;
    PushT neutralPush;
    std::function<pair<PushT, PushT>(const PushT&)> opPush; //calc what to push to children
    std::function<void(PushT&, T&)> opApply; //apply change in vertex
    std::function<PushT(const PushT&, const PushT&)> opPendingCompose; //compose two pending ops

    RMQ(int size, std::function<T(const T&,const T&)> op, T neutral,
        std::function<pair<PushT, PushT>(const PushT&)> opPush, PushT neutralPush,
        std::function<void(PushT&, T&)> opApply,
        std::function<PushT(const PushT&, const PushT&)> opPendingCompose) {
        this->neutral = neutral;
        this->size = size;
        this->op = op;
        mas.assign(4*size, neutral);
        this->opPush = opPush;
        this->opApply = opApply;
        this->opPendingCompose = opPendingCompose;
        this->neutralPush = neutralPush;
        masPush.assign(4*size, neutralPush);
    }

    void setVal(int pos, T val) {
        setValImpl(pos, val, 0, size-1,1);
    }

    void setValImpl(int pos, T val, int l, int r, int v) {
        if (l==r && r==pos) {
            mas[v] = val;
            return;
        }
        if (l>pos || r< pos) return;
        int m = (l+r)/2;
        setValImpl(pos, val, l, m, 2*v);
        setValImpl(pos, val, m+1, r, 2*v+1);
        mas[v] = op(mas[2*v], mas[2*v+1]);
    }

    void modify(int l, int r, PushT d) {
        modifyImpl(l, r, d, 0, size-1, 1);
    }

    void push(int v, bool isLeaf) {
        if (!isLeaf) {
            auto p = opPush(masPush[v]);
            masPush[2*v] = opPendingCompose(masPush[2*v], p.first);
            masPush[2*v+1] = opPendingCompose(masPush[2*v+1], p.second);
        }
        opApply(masPush[v], mas[v]);
    }

    void modifyImpl(int rq_l, int rq_r, ll d, int l, int r, int v){
        push(v, l==r);
        if (rq_l>r || l>rq_r) return;
        if (rq_l<=l && r<=rq_r) {
            masPush[v] = opPendingCompose(masPush[v], d);
            push(v, l==r);
            return;
        }
        int m = (l+r)/2;
        modifyImpl(rq_l, rq_r, d, l, m, 2*v);
        modifyImpl(rq_l, rq_r, d, m+1, r, 2*v+1);
        mas[v] = op(mas[2*v], mas[2*v+1]);
    }

    T query(int l, int r) {
        return queryImpl(l, r, 0, size-1, 1);
    }

    T queryImpl(int rq_l, int rq_r, int l, int r, int v) {
        push(v, l==r);

        if (rq_l>r || l>rq_r) return neutral;
        if (rq_l<=l && r<=rq_r) {
            return mas[v];
        }
        int m = (l+r)/2;
        T ans1 = queryImpl(rq_l, rq_r, l, m, 2*v);
        T ans2 = queryImpl(rq_l, rq_r, m+1, r, 2*v+1);
        return op(ans1, ans2);
    }
};

struct Edge {
    int to;

    int getTo() const {
        return to;
    }

    ll getW() const {
        return 1;
    }
};

struct WEdge {
    int to;
    ll w;

    int getTo() const {
        return to;
    }

    ll getW() const {
        return w;
    }
};

struct None {};

template<typename EdgeType, typename VertType = None>
struct Graph {
    vector<VertType> v;
    vector<vector<EdgeType>> g;
    Graph(int n): g(n), v(n) {};

    void addEdge(int from, int to, EdgeType info) {
        info.to = to;
        g[from].push_back(info);
        info.to = from;
        g[to].push_back(info);
    }

    void addOEdge(int from, int to, EdgeType info) {
        info.to = to;
        g[from].push_back(info);
    }

};

struct PFInfo {
    int par;
    ll dist;

    friend bool operator<(const PFInfo& a, const PFInfo& b) {
        return a.dist<b.dist;
    }
};

template<typename EdgeType, typename VertType>
vector<PFInfo> bfs(const Graph<EdgeType, VertType>& g, int start) {
    vector<PFInfo> res(g.g.size(), {-1, INF64});
    queue<int> s;
    res[start].par = -2;
    res[start].dist = 0;
    s.push(start);
    while (!s.empty()) {
        int v = s.front();
        s.pop();
        for (auto& it: g.g[v]) {
            int to = it.getTo();
            if (res[to].dist == INF64) {
                res[to].par = v;
                res[to].dist = res[v].dist + it.getW();
                s.push(to);
            }
        }
    }
    return res;
}

vector<int> restorePath(const vector<PFInfo>& pfInfo, int to) {
    vector<int> res;
    while (true) {
        res.push_back(to);
        if (pfInfo[to].par == -1) { //Not found
            return {};
        }
        if (pfInfo[to].par == -2) {
            return res;
        }
        to = pfInfo[to].par;
    }
}

struct MyEdge: Edge {
   int roadType;
   MyEdge(int roadType): roadType(roadType) {};
};

int cnt = 0;
void dfs(Graph<MyEdge>& g, vector<pair<int,int>>& segs, vector<int>& oddness, vector<int>& depths, int v = 0, int curCnt = 0, int depth = 0, int p = -1) {
    oddness[cnt] = curCnt;
    depths[cnt] = depth;
    int start = cnt++;

    for (auto& it : g.g[v]) {
        int to = it.getTo();
        if (to == p) continue;
        dfs(g, segs, oddness, depths, to, curCnt ^ it.roadType, depth+1, v);
    }
    segs[v] = {start, cnt-1};
}

void solve() {
    int n;
    cin >> n;
    Graph<MyEdge> g(n);
    vector<pair<int,int>> edges;
    for (int i=0;i<n-1;i++) {
        int u,v, t;
        cin >> u >> v >> t;
        u--; v--;
        g.addEdge(u, v, {t});
        edges.push_back({u,v});
    }
    auto dists = bfs(g, 0);
    int end1 = max_element(dists.begin(), dists.end()) - dists.begin();
    auto dists1 = bfs(g, end1);
    int end2 = max_element(dists1.begin(), dists1.end()) - dists1.begin();
    auto dists2 = bfs(g, end2);

    vector<pair<int,int>> seqFrom1(n), seqFrom2(n);
    vector<int> oddnessFrom1(n), oddnessFrom2(n);
    vector<int> depths1(n), depths2(n);
    cnt = 0;
    dfs(g, seqFrom1, oddnessFrom1, depths1, end1);
    assert(cnt==n);
    RMQ<VertVal, int> rmq1(n,
                           [](const VertVal& a, const VertVal&b) {return VertVal{max(a.lowest0, b.lowest0), max(a.lowest1, b.lowest1)};},
                           VertVal{-1, -1},
                           [](const int& par) {return pair<bool, bool>(par, par);},
                           false,
                           [](int& a, VertVal& b) {if (a) swap(b.lowest0, b.lowest1); a = false;},

                           [](const int& a, const int& b) {return a^b;});

    for (int i=0;i<n;i++) {
        if (oddnessFrom1[i]) {
            rmq1.setVal(i, {-1, depths1[i]});
        } else {
            rmq1.setVal(i, {depths1[i], -1});
        }
    }

    cnt = 0;
    dfs(g, seqFrom2, oddnessFrom2, depths2, end2);
    assert(cnt==n);
    RMQ<VertVal, int> rmq2(n,
                           [](const VertVal& a, const VertVal&b) {return VertVal{max(a.lowest0, b.lowest0), max(a.lowest1, b.lowest1)};},
                           VertVal{-1, -1},
                           [](const int& par) {return pair<bool, bool>(par, par);},
                           false,
                           [](int& a, VertVal& b) {if (a) swap(b.lowest0, b.lowest1); a = false;},

                           [](const int& a, const int& b) {return a^b;});

    auto tmp = rmq1.query(0,1);
    for (int i=0;i<n;i++) {
        if (oddnessFrom2[i]) {
            rmq2.setVal(i, {-1, depths2[i]});
        } else {
            rmq2.setVal(i, {depths2[i], -1});
        }
    }

    int m;
    cin >> m;
    for (int i=0;i<m;i++) {
        int id;
        cin >> id;
        id--;
        auto p = edges[id];
        int u = p.first;
        int v = p.second;

        int root = -1;
        if (dists1[u].par == v) {
            root = u;
        } else if (dists1[v].par == u) {
            root = v;
        } else assert(false);
        auto seg = seqFrom1[root];
        rmq1.modify(seg.first, seg.second, true);

        root = -1;
        if (dists2[u].par == v) {
            root = u;
        } else if (dists2[v].par == u) {
            root = v;
        } else assert(false);
        seg = seqFrom2[root];
        rmq2.modify(seg.first, seg.second, true);

        auto res1 = rmq1.query(0, n-1);
        auto res2 = rmq2.query(0, n-1);
        ll res = max(res1.lowest0, res2.lowest0);
        cout << res << "\n";
    }

}

int main(int argc, char** argv) {

    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cout << setprecision(2) << fixed;
    int t;
    //cin >> t;
    //for (int i=0;i<t;i++)
//      while (1)
        solve();

    return 0;
}


//sobskdrbhvk
//remember...
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

#define PB push_back
#define MP make_pair
#define L first
#define R second
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define time tim

const int maxn = 500 * 1000 + 10;
int seg[maxn << 2][2][2];
bool laz[maxn << 2];
int h[2][maxn];
vector<int> adj[maxn];
int frm[maxn],
    too[maxn],
    vert[maxn],
    st[maxn],
    ft[maxn];
bool col[maxn];
int n, time;

void dfs(int u, int *h, bool fill_time, int p = -1) {
    if (p == -1)
        h[u] = 0;
    if (fill_time) {
        vert[time] = u;
        st[u] = time++;
    }
    for (auto e: adj[u]) {
        int v = frm[e] ^ too[e] ^ u;
        if (v ^ p) {
            h[v] = h[u] + 1;
            dfs(v, h, fill_time, u);
        }
    }
    if (fill_time)
        ft[u] = time;
}

void merge(int dst[][2], int le[][2], int ri[][2]) {
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < 2; j++)
            dst[i][j] = max(le[i][j], ri[i][j]);
}

void build(int l = 0, int r = n, int id = 1) {
    if (r - l == 1) {
        memset(seg[id], 0, sizeof seg[id]);
        seg[id][0][0] = h[0][vert[l]];
        seg[id][0][1] = h[1][vert[l]];
        return;
    }
    int mid = (l + r) >> 1;
    build(l, mid, id << 1 | 0);
    build(mid, r, id << 1 | 1);
    merge(seg[id], seg[id << 1 | 0], seg[id << 1 | 1]);
}

bool get_col(int idx, int l = 0, int r = n, int id = 1) {
    if (idx < l or r <= idx)
        return 0;
    if (r - l == 1)
        return laz[id];
    int mid = (l + r) >> 1;
    return get_col(idx, l, mid, id << 1 | 0)
        ^ get_col(idx, mid, r, id << 1 | 1)
        ^ laz[id];
}

void invert(int st, int en, int l = 0, int r = n, int id = 1) {
    if (st >= r or en <= l)
        return;
    if (st <= l and r <= en) {
        swap(seg[id][0][0], seg[id][1][0]);
        swap(seg[id][0][1], seg[id][1][1]);
        laz[id] ^= 1;
        return;
    }
    int mid = (l + r) >> 1;
    invert(st, en, l, mid, id << 1 | 0);
    invert(st, en, mid, r, id << 1 | 1);
    merge(seg[id], seg[id << 1 | 0], seg[id << 1 | 1]);
    if (laz[id]) {
        swap(seg[id][0][0], seg[id][1][0]);
        swap(seg[id][0][1], seg[id][1][1]);
    }
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i + 1 < n; i++) {
        int fi, se, th;
        cin >> fi >> se >> th;
        fi--, se--;
        frm[i] = fi;
        too[i] = se;
        col[i] = th;
        adj[fi].PB(i);
        adj[se].PB(i);
    }
    dfs(0, h[0], true);
    for (int i = 0; i + 1 < n; i++)
        if (h[0][frm[i]] > h[0][too[i]]) {
            swap(frm[i], too[i]);
        }

    int p1 = max_element(h[0], h[0] + n) - h[0];
    dfs(p1, h[0], false);
    int p2 = max_element(h[0], h[0] + n) - h[0];
    dfs(p2, h[1], false);

    build();
    for (int i = 0; i + 1 < n; i++)
        if (col[i])
            invert(st[too[i]], ft[too[i]]);

    int q;
    cin >> q;
    while (q--) {
        int id;
        cin >> id, id--;
        invert(st[too[id]], ft[too[id]]);
        int ans = 0;
        int c1 = get_col(st[p1]);
        int c2 = get_col(st[p2]);
        if (c1 == c2)
            cout << h[0][p2] << '\n';
        else
            cout << max(seg[1][c1][0], seg[1][c2][1]) << '\n';
    }
	return 0;
}


//sobskdrbhvk
//remember...
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

#define PB push_back
#define MP make_pair
#define L first
#define R second
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define time tim

const int maxn = 500 * 1000 + 10;
int seg[maxn << 2][2][2];
bool laz[maxn << 2];
int h[2][maxn];
vector<int> adj[maxn];
int frm[maxn],
    too[maxn],
    st[maxn],
    ft[maxn];
bool col[maxn];
int n, time;

void dfs(int u, int *h, bool fill_time, int p = -1) {
    if (p == -1)
        h[u] = 0;
    if (fill_time)
        st[u] = time++;
    for (auto e: adj[u]) {
        int v = frm[e] ^ too[e] ^ u;
        if (v ^ p) {
            h[v] = h[u] + 1;
            dfs(v, h, fill_time, u);
        }
    }
    if (fill_time)
        ft[u] = time;
}

void merge(int dst[][2], int le[][2], int ri[][2]) {
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < 2; j++)
            dst[i][j] = max(le[i][j], ri[i][j]);
}

void build(int l = 0, int r = n, int id = 1) {
    if (r - l == 1) {
        memset(seg[id], 0, sizeof seg[id]);
        seg[id][0][0] = h[0][l];
        seg[id][0][1] = h[1][l];
        return;
    }
    int mid = (l + r) >> 1;
    build(l, mid, id << 1 | 0);
    build(mid, r, id << 1 | 1);
    merge(seg[id], seg[id << 1 | 0], seg[id << 1 | 1]);
}

bool get_col(int idx, int l = 0, int r = n, int id = 1) {
    if (idx < l or r <= idx)
        return 0;
    if (r - l == 1)
        return laz[id];
    int mid = (l + r) >> 1;
    return get_col(idx, l, mid, id << 1 | 0)
        ^ get_col(idx, mid, r, id << 1 | 1)
        ^ laz[id];
}

void invert(int st, int en, int l = 0, int r = n, int id = 1) {
    if (st >= r or en <= l)
        return;
    if (st <= l and r <= en) {
        swap(seg[id][0][0], seg[id][1][0]);
        swap(seg[id][0][1], seg[id][1][1]);
        laz[id] ^= 1;
        return;
    }
    int mid = (l + r) >> 1;
    invert(st, en, l, mid, id << 1 | 0);
    invert(st, en, mid, r, id << 1 | 1);
    merge(seg[id], seg[id << 1 | 0], seg[id << 1 | 1]);
    if (laz[id]) {
        swap(seg[id][0][0], seg[id][1][0]);
        swap(seg[id][0][1], seg[id][1][1]);
    }
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i + 1 < n; i++) {
        int fi, se, th;
        cin >> fi >> se >> th;
        fi--, se--;
        frm[i] = fi;
        too[i] = se;
        col[i] = th;
        adj[fi].PB(i);
        adj[se].PB(i);
    }
    dfs(0, h[0], true);
    for (int i = 0; i + 1 < n; i++)
        if (h[0][frm[i]] > h[0][too[i]]) {
            swap(frm[i], too[i]);
        }

    int p1 = max_element(h[0], h[0] + n) - h[0];
    dfs(p1, h[0], false);
    int p2 = max_element(h[0], h[0] + n) - h[0];
    dfs(p2, h[1], false);

    build();
    for (int i = 0; i + 1 < n; i++)
        if (col[i])
            invert(st[too[i]], ft[too[i]]);

    int q;
    cin >> q;
    while (q--) {
        int id;
        cin >> id, id--;
        invert(st[too[id]], ft[too[id]]);
        int ans = 0;
        int c1 = get_col(st[p1]);
        int c2 = get_col(st[p2]);
        if (c1 == c2)
            cout << h[0][p2] << '\n';
        else
            cout << max(seg[1][c1][0], seg[1][c2][1]) << '\n';
    }
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
#define N 500012
#define U 1000012
inline int read(){
	int t=0;char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,c[N],h[N],cnt=1,de[N],L[N],R[N],dfst=0,rev[N],le[N],dft=0,g[U][20],Log[U];
struct Edge{int to,next,s;}e[N<<1];
inline void AddEdge(int x,int y,int v){e[++cnt]=(Edge){y,h[x],v};h[x]=cnt;}
void dfs(int x,int prt)
{
	de[x]=de[prt]+1;rev[L[x]=++dfst]=x;g[le[x]=++dft][0]=de[x];int i,y;
	for(i=h[x];i;i=e[i].next)if((y=e[i].to)!=prt)c[y]=c[x]^e[i].s,dfs(y,x),g[++dft][0]=de[x];R[x]=dfst;
}
inline int dlc(int x,int y){x=le[x];y=le[y];(x>y)?(x^=y^=x^=y):0;int p=Log[y-x+1];return min(g[x][p],g[y-(1<<p)+1][p]);}
inline int di(int x,int y){return de[x]+de[y]-(dlc(x,y)<<1);}
struct Dia{
	int x,y,v;
	inline Dia(int xx=0,int yy=0,int vv=0){x=xx;y=yy;v=vv;}
	inline Dia operator+(const Dia &b)const
	{
		if(!x)return b;if(!b.x)return *this;int ox=x,oy=y,ov=v,v1;if(b.v>ov)ox=b.x,oy=b.y,ov=b.v;
		if((v1=di(x,b.x))>ov)ov=v1,ox=x,oy=b.x;
		if((v1=di(x,b.y))>ov)ov=v1,ox=x,oy=b.y;
		if((v1=di(y,b.x))>ov)ov=v1,ox=y,oy=b.x;
		if((v1=di(y,b.y))>ov)ov=v1,ox=y,oy=b.y;return Dia(ox,oy,ov);
	}
}s[N<<2][2];
bool re[N<<2];
inline void pus(int x){s[x][0]=s[x<<1][0]+s[x<<1|1][0];s[x][1]=s[x<<1][1]+s[x<<1|1][1];}
inline void Add(int x){re[x]^=1;swap(s[x][0],s[x][1]);}
inline void pd(int x){if(re[x])Add(x<<1),Add(x<<1|1),re[x]=0;}
void build(int p,int l,int r)
{
	if(l==r){int v=c[rev[l]];s[p][v]=Dia(rev[l],rev[l],0);s[p][v^1]=Dia(0,0,0);return;}int mid=(l+r)>>1;
	build(p<<1,l,mid);build(p<<1|1,mid+1,r);pus(p);
}
void change(int p,int l,int r,int L,int R)
{
	if((R<l)||(r<L))return;if((L<=l)&&(r<=R)){Add(p);return;}pd(p);int mid=(l+r)>>1;
	change(p<<1,l,mid,L,R);change(p<<1|1,mid+1,r,L,R);pus(p);
}
int main(){
	Log[0]=-1;for(int i=1;i<U;i++)Log[i]=Log[i>>1]+1;
	n=read();int i,j,x,y,v;for(i=1;i<n;i++){x=read(),y=read(),v=read();AddEdge(x,y,v);AddEdge(y,x,v);}dfs(1,0);
	for(j=1;j<=Log[dft];j++)
	for(i=1;i+(1<<j)-1<=dft;i++)g[i][j]=min(g[i][j-1],g[i+(1<<(j-1))][j-1]);build(1,1,dfst);
	m=read();
	while(m--)
	{
		v=read();v<<=1;x=(de[e[v].to]<de[e[v^1].to])?(e[v^1].to):(e[v].to);
		change(1,1,dfst,L[x],R[x]);printf("%d\n",max(s[1][0].v,s[1][1].v));
	}return 0;
}


#include <bits/stdc++.h>
#include <unistd.h>

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define UQ(x) (x).resize(distance((x).begin(),unique(x.begin(),x.end())))

using namespace std;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a,ll m,ll mod){
    ll ans = 1;
    while(m){
        if(m%2) ans *= a, ans %= (mod);
        a = (a*a) % mod;
        m >>= 1;
    }
    return ans;
}

struct custom_hash {  // Credits: https://codeforces.com/blog/entry/62393
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM =
            chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    size_t operator()(pair<int64_t, int64_t> Y) const {
        static const uint64_t FIXED_RANDOM =
            chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM);
    }
};

const long long inf = 1e18;
const long long M = 1000000007;
const long long N = 5e5 + 100;

ll n;
vll adj[N];
unordered_map<pll,ll,custom_hash> mp;

pair<ll,ll> dfs1(ll node, ll par) {
    ll mx = 0, ans = node;
    pll tmp;
    for(auto i : adj[node]) {
        if(i == par) continue;
        tmp = dfs1(i, node);
        if(tmp.F > mx) mx = tmp.F, ans = tmp.S;
    }
    return {mx + 1, ans};
}

struct segmentTree {
    ll dist[N],a[N],st[4*N][2],lazy[4*N], root, tin[N], tout[N], time;

    void lazyp(ll node){
        if(!lazy[node]) return;
        lazy[2*node] ^= 1;
        lazy[2*node + 1] ^= 1;
        swap(st[2 * node][0], st[2 * node][1]);
        swap(st[2 * node + 1][0], st[2 * node + 1][1]);
        lazy[node]=0;
    }

    void build(ll node,ll l,ll r){
        if(l==r){
            st[node][0] = st[node][1] = 0;
            st[node][a[l]] = dist[l];
            return;
        }
        ll mid=(l+r)/2;
        build(2*node,l,mid);
        build(2*node+1,mid+1,r);
        st[node][0] = max(st[2 * node][0], st[2 * node + 1][0]);
        st[node][1] = max(st[2 * node][1], st[2 * node + 1][1]);
        return;
    }

    void update(ll node,ll l,ll r,ll sb,ll se){
        if(sb>r||se<l) return;
        if(sb>=l&&se<=r){
            lazy[node] ^= 1;
            swap(st[node][0], st[node][1]);
            return;
        }
        lazyp(node);
        ll mid=(sb+se)/2;
        update(2*node,l,r,sb,mid);
        update(2*node+1,l,r,mid+1,se);
        st[node][0] = max(st[2 * node][0], st[2 * node + 1][0]);
        st[node][1] = max(st[2 * node][1], st[2 * node + 1][1]);
    }

    void dfs(ll node, ll par, ll p, ll d) {
        ++time;
        tin[node] = time;
        a[time] = p;
        dist[time] = d;
        for(auto i : adj[node]) {
            if(i == par) continue;
            dfs(i, node, p ^ mp[{i, node}], d + 1);
        }
        tout[node] = time;
    }

    segmentTree(ll root) {
        time = -1;
        this->root = root;
        dfs(root, -1, 0, 0);
        build(1,0,n - 1);
    }
};

void solve(){
    ll i,j,_,m;
    cin >> n;
    ll a, b;
    vpll v;
    rep(i,0,n - 1) cin >> a >> b >> j, --a, --b, v.pb({a, b}), adj[a].pb(b), adj[b].pb(a), mp[{a,b}] = j, mp[{b,a}] = j;
    a = dfs1(0, -1).S;
    b = dfs1(a, -1).S;
    swap(a, b);
    segmentTree st1(a), st2(b);
    cin >> m;
    while(m--) {
        cin >> j, --j;
        if(st1.tin[v[j].F] > st1.tin[v[j].S]) st1.update(1, st1.tin[v[j].F], st1.tout[v[j].F], 0, n - 1);
        else st1.update(1, st1.tin[v[j].S], st1.tout[v[j].S], 0, n - 1);
        if(st2.tin[v[j].F] > st2.tin[v[j].S]) st2.update(1, st2.tin[v[j].F], st2.tout[v[j].F], 0, n - 1);
        else st2.update(1, st2.tin[v[j].S], st2.tout[v[j].S], 0, n - 1);
        cout << max(st1.st[1][0], st2.st[1][0]) << endl;

    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll T=1;
    // cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 1e5+10;
///===========================================  template  =======================================================

vector<pair<int, int>> adj[nmax];

int depth[nmax];
int edge[nmax];
int pathDepth[nmax];
int clk = 0, euler[nmax];
pair<int, int> ranges[nmax];

void dfs(int u, int par, int e){
    depth[u] = (par == -1)? 1 : depth[par] + 1;
    pathDepth[u] = (par == -1)? 0 : (pathDepth[par] ^ e);

    euler[++clk] = u;
    int last = clk;
    for(auto p : adj[u]){
        if(p.first == par) continue;
        dfs(p.first, u, edge[p.second]);
        euler[++clk] = u;

        ranges[p.second] = {last+1, clk-1};
        last = clk;
    }
    return;
}

#define lc (id<<1)
#define rc ((id<<1)|1)

struct node{
    int m;
    int l_r[2], lm[2], mr[2], lmr[2];
};

inline void op(node &a, int x, node &b, int y, node &c){

    for(int z = 0; z<2; z++){
        int za = z^x, zb = z^y;

//        if(b.l_r[zb] == -1e8){
//            c.lmr[z] = a.lmr[za], c.lm[z] = a.lm[za], c.mr[z] = a.mr[za], c.l_r[z] = a.l_r[za];
//            continue;
//        }
//        if(a.l_r[za] == -1e8){
//            c.lmr[z] = b.lmr[zb], c.lm[z] = a.lm[zb], c.mr[z] = a.mr[zb], c.l_r[z] = b.l_r[zb];
//            continue;
//        }

        c.lmr[z] = max({a.lm[za] + b.l_r[zb], a.l_r[za] + b.mr[zb], a.lmr[za], b.lmr[zb]});
        c.lm[z] = max({a.l_r[za] - 2*b.m, a.lm[za], b.lm[zb]});
        c.mr[z] = max({b.l_r[zb] - 2*a.m, a.mr[za], b.mr[zb]});
        c.l_r[z] = max({a.l_r[za], b.l_r[zb]});
    }

    c.m = min(a.m, b.m);
}

node tree[4*nmax];
int flip[nmax];

void build(int id, int l, int r)
{
    if(l == r)
    {
        int u = euler[l];
        tree[id].m = depth[u];
        tree[id].l_r[pathDepth[u]] = depth[u];
        tree[id].l_r[pathDepth[u]^1] = -1e8;
        tree[id].lm[pathDepth[u]] = -depth[u];
        tree[id].lm[pathDepth[u]^1] = -1e8;
        tree[id].mr[pathDepth[u]] = -depth[u];
        tree[id].mr[pathDepth[u]^1] = -1e8;
        tree[id].lmr[pathDepth[u]] = 0;
        tree[id].lmr[pathDepth[u]^1] = -1e8;
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

void update(int id, int l, int r, int L, int R)
{
    if(L <= l && r <= R){
        flip[id] ^= 1;
        return;
    }

    if(r < L || R < l){
        return;
    }

    int mid = (l+r)/2;
    update(lc, l, mid, L, R);
    update(rc, mid+1, r, L, R);

    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 1; i<=n-1; i++){
        int u, v, x;
        cin>>u>>v>>x;
        adj[u].emplace_back(v, i);
        adj[v].emplace_back(u, i);
        edge[i] = x;
    }

    dfs(1, -1, 0);

//    debug(), "euler ", range(euler+1, euler+clk+1);
//    debug(), "depths ", range(depth+1, depth+n);

    build(1, 1, clk);

//    cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

//    debug(), dbg(tree[5].lm[1]);

    int q;
    cin>>q;
    for(int i = 0; i<q; i++){
        int e;
        cin>>e;

        update(1, 1, clk, ranges[e].first, ranges[e].second);

        cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

//        debug(), dbg(tree[2].lm[1]);
    }

    return 0;
}
/*
9
2 7 0
1 5 0
6 8 0
4 9 0
2 5 1
7 8 0
2 3 1
4 2 0
0

4
1 2 1
2 3 0
3 4 0
0

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

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 1e5+10;
///===========================================  template  =======================================================

vector<pair<int, int>> adj[nmax];

int depth[nmax];
int edge[nmax];
int pathDepth[nmax];
int clk = 0, euler[nmax];
pair<int, int> ranges[nmax];

void dfs(int u, int par, int e){
    depth[u] = (par == -1)? 1 : depth[par] + 1;
    pathDepth[u] = (par == -1)? 0 : (pathDepth[par] ^ e);

    euler[++clk] = u;
    int last = clk;
    for(auto p : adj[u]){
        if(p.first == par) continue;
        dfs(p.first, u, edge[p.second]);
        euler[++clk] = u;

        ranges[p.second] = {last+1, clk-1};
        last = clk;
    }
    return;
}

#define lc (id<<1)
#define rc ((id<<1)|1)

struct node{
    int l_r[2], lm[2], mr[2], lmr[2];
};

inline void op(node &a, int x, node &b, int y, node &c){

    int ma = max(a.l_r[0], a.l_r[1]);
    int mb = max(b.l_r[0], b.l_r[1]);

    for(int z = 0; z<2; z++){
        int za = z^x, zb = z^y;

//        if(b.l_r[zb] == -1e8){
//            c.lmr[z] = a.lmr[za], c.lm[z] = a.lm[za], c.mr[z] = a.mr[za], c.l_r[z] = a.l_r[za];
//            continue;
//        }
//        if(a.l_r[za] == -1e8){
//            c.lmr[z] = b.lmr[zb], c.lm[z] = a.lm[zb], c.mr[z] = a.mr[zb], c.l_r[z] = b.l_r[zb];
//            continue;
//        }

        c.lmr[z] = max({a.lm[za] + b.l_r[zb], a.l_r[za] + b.mr[zb], a.lmr[za], b.lmr[zb]});
        c.lm[z] = max({a.l_r[za] - 2*mb, a.lm[za], b.lm[zb]});
        c.mr[z] = max({b.l_r[zb] - 2*ma, a.mr[za], b.mr[zb]});
        c.l_r[z] = max({a.l_r[za], b.l_r[zb]});
    }
}

node tree[4*nmax];
int flip[nmax];

void build(int id, int l, int r)
{
    if(l == r)
    {
        int u = euler[l];
        tree[id].l_r[pathDepth[u]] = depth[u];
        tree[id].l_r[pathDepth[u]^1] = -1e8;
        tree[id].lm[pathDepth[u]] = -depth[u];
        tree[id].lm[pathDepth[u]^1] = -1e8;
        tree[id].mr[pathDepth[u]] = -depth[u];
        tree[id].mr[pathDepth[u]^1] = -1e8;
        tree[id].lmr[pathDepth[u]] = 0;
        tree[id].lmr[pathDepth[u]^1] = -1e8;
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

void update(int id, int l, int r, int L, int R)
{
    if(L <= l && r <= R){
        flip[id] ^= 1;
        return;
    }

    if(r < L || R < l){
        return;
    }

    int mid = (l+r)/2;
    update(lc, l, mid, L, R);
    update(rc, mid+1, r, L, R);

    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 1; i<=n-1; i++){
        int u, v, x;
        cin>>u>>v>>x;
        adj[u].emplace_back(v, i);
        adj[v].emplace_back(u, i);
        edge[i] = x;
    }

    dfs(1, -1, 0);

//    debug(), "euler ", range(euler+1, euler+clk+1);
//    debug(), "ranges ", range(ranges+1, ranges+n);

    build(1, 1, clk);

//    cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

    int q;
    cin>>q;
    for(int i = 0; i<q; i++){
        int e;
        cin>>e;

        update(1, 1, clk, ranges[e].first, ranges[e].second);

        cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

//        debug(), dbg(tree[2].lm[1]);
    }

    return 0;
}
/*
3
1 2 1
1 3 0
1
2

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 1e6+10;
///===========================================  template  =======================================================

vector<pair<int, int>> adj[nmax];

int depth[nmax];
int edge[nmax];
int pathDepth[nmax];
int clk = 0, euler[nmax];
pair<int, int> ranges[nmax];

void dfs(int u, int par, int e){
    depth[u] = (par == -1)? 1 : depth[par] + 1;
    pathDepth[u] = (par == -1)? 0 : (pathDepth[par] ^ e);

    euler[++clk] = u;
    int last = clk;
    for(auto p : adj[u]){
        if(p.first == par) continue;
        dfs(p.first, u, edge[p.second]);
        euler[++clk] = u;

        ranges[p.second] = {last+1, clk-1};
        last = clk;
    }
    return;
}

#define lc (id<<1)
#define rc ((id<<1)|1)

struct node{
    int m;
    int l_r[2], lm[2], mr[2], lmr[2];
};

inline void op(node &a, int x, node &b, int y, node &c){

    for(int z = 0; z<2; z++){
        int za = z^x, zb = z^y;

        c.lmr[z] = max({a.lm[za] + b.l_r[zb], a.l_r[za] + b.mr[zb], a.lmr[za], b.lmr[zb]});
        c.lm[z] = max({a.l_r[za] - 2*b.m, a.lm[za], b.lm[zb]});
        c.mr[z] = max({b.l_r[zb] - 2*a.m, a.mr[za], b.mr[zb]});
        c.l_r[z] = max({a.l_r[za], b.l_r[zb]});
    }

    c.m = min(a.m, b.m);
}

node tree[4*nmax];
int flip[4*nmax];

void build(int id, int l, int r)
{
    assert(id < 4*nmax);
    if(l == r)
    {
        int u = euler[l];
        tree[id].m = depth[u];
        tree[id].l_r[pathDepth[u]] = depth[u];
        tree[id].l_r[pathDepth[u]^1] = -1e8;
        tree[id].lm[pathDepth[u]] = -depth[u];
        tree[id].lm[pathDepth[u]^1] = -1e8;
        tree[id].mr[pathDepth[u]] = -depth[u];
        tree[id].mr[pathDepth[u]^1] = -1e8;
        tree[id].lmr[pathDepth[u]] = 0;
        tree[id].lmr[pathDepth[u]^1] = -1e8;
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

void update(int id, int l, int r, int L, int R)
{
    assert(id < 4*nmax);
    if(L <= l && r <= R){
        flip[id] ^= 1;
        return;
    }

    if(r < L || R < l){
        return;
    }

    int mid = (l+r)/2;
    update(lc, l, mid, L, R);
    update(rc, mid+1, r, L, R);

    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 1; i<=n-1; i++){
        int u, v, x;
        cin>>u>>v>>x;
        adj[u].emplace_back(v, i);
        adj[v].emplace_back(u, i);
        edge[i] = x;
    }

    dfs(1, -1, 0);

    build(1, 1, clk);

//    if(n == 500000)
//        cout<<__LINE__<<"hoise"<<endl;

//    cerr<<clk<<endl;

    int q;
    cin>>q;
    for(int i = 0; i<q; i++){
        int e;
        cin>>e;

        update(1, 1, clk, ranges[e].first, ranges[e].second);

        cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

    }

    return 0;
}
/*
9
2 7 0
1 5 0
6 8 0
4 9 0
2 5 1
7 8 0
2 3 1
4 2 0
0

4
1 2 1
2 3 0
3 4 0
0

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

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 1e6+10;
///===========================================  template  =======================================================

vector<pair<int, int>> adj[nmax];

int depth[nmax];
int edge[nmax];
int pathDepth[nmax];
int clk = 0, euler[nmax];
pair<int, int> ranges[nmax];

void dfs(int u, int par, int e){
    depth[u] = (par == -1)? 1 : depth[par] + 1;
    pathDepth[u] = (par == -1)? 0 : (pathDepth[par] ^ e);

    euler[++clk] = u;
    int last = clk;
    for(auto p : adj[u]){
        if(p.first == par) continue;
        dfs(p.first, u, edge[p.second]);
        euler[++clk] = u;

        ranges[p.second] = {last+1, clk-1};
        last = clk;
    }
    return;
}

#define lc (id<<1)
#define rc ((id<<1)|1)

struct node{
    int m;
    int l_r[2], lm[2], mr[2], lmr[2];
};

inline void op(node &a, int x, node &b, int y, node &c){

    for(int z = 0; z<2; z++){
        int za = z^x, zb = z^y;

        c.lmr[z] = max({a.lm[za] + b.l_r[zb], a.l_r[za] + b.mr[zb], a.lmr[za], b.lmr[zb]});
        c.lm[z] = max({a.l_r[za] - 2*b.m, a.lm[za], b.lm[zb]});
        c.mr[z] = max({b.l_r[zb] - 2*a.m, a.mr[za], b.mr[zb]});
        c.l_r[z] = max({a.l_r[za], b.l_r[zb]});
    }

    c.m = min(a.m, b.m);
}

node tree[4*nmax];
int flip[nmax];

void build(int id, int l, int r)
{
    assert(id < 4*nmax);
    if(l == r)
    {
        int u = euler[l];
        tree[id].m = depth[u];
        tree[id].l_r[pathDepth[u]] = depth[u];
        tree[id].l_r[pathDepth[u]^1] = -1e8;
        tree[id].lm[pathDepth[u]] = -depth[u];
        tree[id].lm[pathDepth[u]^1] = -1e8;
        tree[id].mr[pathDepth[u]] = -depth[u];
        tree[id].mr[pathDepth[u]^1] = -1e8;
        tree[id].lmr[pathDepth[u]] = 0;
        tree[id].lmr[pathDepth[u]^1] = -1e8;
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

void update(int id, int l, int r, int L, int R)
{
    assert(id < 4*nmax);
    if(L <= l && r <= R){
        flip[id] ^= 1;
        return;
    }

    if(r < L || R < l){
        return;
    }

    int mid = (l+r)/2;
    update(lc, l, mid, L, R);
    update(rc, mid+1, r, L, R);

    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 1; i<=n-1; i++){
        int u, v, x;
        cin>>u>>v>>x;
        adj[u].emplace_back(v, i);
        adj[v].emplace_back(u, i);
        edge[i] = x;
    }

    dfs(1, -1, 0);

    if(n == 500000)
        cout<<__LINE__<<"hoise"<<endl;

    assert(clk < nmax);

//    debug(), "euler ", range(euler+1, euler+clk+1);
//    debug(), "depths ", range(depth+1, depth+n);

    build(1, 1, clk);

    if(n == 500000)
        cout<<__LINE__<<"hoise"<<endl;

//    cerr<<clk<<endl;

    int q;
    cin>>q;
    for(int i = 0; i<q; i++){
        int e;
        cin>>e;

        update(1, 1, clk, ranges[e].first, ranges[e].second);

        cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

    }

    return 0;
}
/*
9
2 7 0
1 5 0
6 8 0
4 9 0
2 5 1
7 8 0
2 3 1
4 2 0
0

4
1 2 1
2 3 0
3 4 0
0

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

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 1e6+10;
///===========================================  template  =======================================================

vector<pair<int, int>> adj[nmax];

int depth[nmax];
int edge[nmax];
int pathDepth[nmax];
int clk = 0, euler[nmax];
pair<int, int> ranges[nmax];

void dfs(int u, int par, int e){
    depth[u] = (par == -1)? 1 : depth[par] + 1;
    pathDepth[u] = (par == -1)? 0 : (pathDepth[par] ^ e);

    euler[++clk] = u;
    int last = clk;
    for(auto p : adj[u]){
        if(p.first == par) continue;
        dfs(p.first, u, edge[p.second]);
        euler[++clk] = u;

        ranges[p.second] = {last+1, clk-1};
        last = clk;
    }
    return;
}

#define lc (id<<1)
#define rc ((id<<1)|1)

struct node{
    int m;
    int l_r[2], lm[2], mr[2], lmr[2];
};

inline void op(node &a, int x, node &b, int y, node &c){

    for(int z = 0; z<2; z++){
        int za = z^x, zb = z^y;

        c.lmr[z] = max({a.lm[za] + b.l_r[zb], a.l_r[za] + b.mr[zb], a.lmr[za], b.lmr[zb]});
        c.lm[z] = max({a.l_r[za] - 2*b.m, a.lm[za], b.lm[zb]});
        c.mr[z] = max({b.l_r[zb] - 2*a.m, a.mr[za], b.mr[zb]});
        c.l_r[z] = max({a.l_r[za], b.l_r[zb]});
    }

    c.m = min(a.m, b.m);
}

node tree[4*nmax];
int flip[nmax];

void build(int id, int l, int r)
{
    assert(id < 4*nmax);
    if(l == r)
    {
        int u = euler[l];
        tree[id].m = depth[u];
        tree[id].l_r[pathDepth[u]] = depth[u];
        tree[id].l_r[pathDepth[u]^1] = -1e8;
        tree[id].lm[pathDepth[u]] = -depth[u];
        tree[id].lm[pathDepth[u]^1] = -1e8;
        tree[id].mr[pathDepth[u]] = -depth[u];
        tree[id].mr[pathDepth[u]^1] = -1e8;
        tree[id].lmr[pathDepth[u]] = 0;
        tree[id].lmr[pathDepth[u]^1] = -1e8;
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

void update(int id, int l, int r, int L, int R)
{
    assert(id < 4*nmax);
    if(L <= l && r <= R){
        flip[id] ^= 1;
        return;
    }

    if(r < L || R < l){
        return;
    }

    int mid = (l+r)/2;
    update(lc, l, mid, L, R);
    update(rc, mid+1, r, L, R);

    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 1; i<=n-1; i++){
        int u, v, x;
        cin>>u>>v>>x;
        adj[u].emplace_back(v, i);
        adj[v].emplace_back(u, i);
        edge[i] = x;
    }

    dfs(1, -1, 0);

    if(n == 500000)
        cout<<"hoise"<<endl;

    assert(clk < nmax);

//    debug(), "euler ", range(euler+1, euler+clk+1);
//    debug(), "depths ", range(depth+1, depth+n);

    build(1, 1, clk);

    if(n == 500000)
        cout<<"hoise"<<endl;

//    cerr<<clk<<endl;

    int q;
    cin>>q;
    for(int i = 0; i<q; i++){
        int e;
        cin>>e;

        update(1, 1, clk, ranges[e].first, ranges[e].second);

        cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

    }

    return 0;
}
/*
9
2 7 0
1 5 0
6 8 0
4 9 0
2 5 1
7 8 0
2 3 1
4 2 0
0

4
1 2 1
2 3 0
3 4 0
0

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

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 1e6+10;
///===========================================  template  =======================================================

vector<pair<int, int>> adj[nmax];

int depth[nmax];
int edge[nmax];
int pathDepth[nmax];
int clk = 0, euler[nmax];
pair<int, int> ranges[nmax];

void dfs(int u, int par, int e){
    depth[u] = (par == -1)? 1 : depth[par] + 1;
    pathDepth[u] = (par == -1)? 0 : (pathDepth[par] ^ e);

    euler[++clk] = u;
    int last = clk;
    for(auto p : adj[u]){
        if(p.first == par) continue;
        dfs(p.first, u, edge[p.second]);
        euler[++clk] = u;

        ranges[p.second] = {last+1, clk-1};
        last = clk;
    }
    return;
}

#define lc (id<<1)
#define rc ((id<<1)|1)

struct node{
    int m;
    int l_r[2], lm[2], mr[2], lmr[2];
};

inline void op(node &a, int x, node &b, int y, node &c){

    for(int z = 0; z<2; z++){
        int za = z^x, zb = z^y;

        c.lmr[z] = max({a.lm[za] + b.l_r[zb], a.l_r[za] + b.mr[zb], a.lmr[za], b.lmr[zb]});
        c.lm[z] = max({a.l_r[za] - 2*b.m, a.lm[za], b.lm[zb]});
        c.mr[z] = max({b.l_r[zb] - 2*a.m, a.mr[za], b.mr[zb]});
        c.l_r[z] = max({a.l_r[za], b.l_r[zb]});
    }

    c.m = min(a.m, b.m);
}

node tree[4*nmax];
int flip[nmax];

void build(int id, int l, int r)
{
    assert(id < 4*nmax);
    if(l == r)
    {
        int u = euler[l];
        tree[id].m = depth[u];
        tree[id].l_r[pathDepth[u]] = depth[u];
        tree[id].l_r[pathDepth[u]^1] = -1e8;
        tree[id].lm[pathDepth[u]] = -depth[u];
        tree[id].lm[pathDepth[u]^1] = -1e8;
        tree[id].mr[pathDepth[u]] = -depth[u];
        tree[id].mr[pathDepth[u]^1] = -1e8;
        tree[id].lmr[pathDepth[u]] = 0;
        tree[id].lmr[pathDepth[u]^1] = -1e8;
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

void update(int id, int l, int r, int L, int R)
{
    assert(id < 4*nmax);
    if(L <= l && r <= R){
        flip[id] ^= 1;
        return;
    }

    if(r < L || R < l){
        return;
    }

    int mid = (l+r)/2;
    update(lc, l, mid, L, R);
    update(rc, mid+1, r, L, R);

    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 1; i<=n-1; i++){
        int u, v, x;
        cin>>u>>v>>x;
        adj[u].emplace_back(v, i);
        adj[v].emplace_back(u, i);
        edge[i] = x;
    }

    dfs(1, -1, 0);

    assert(clk < nmax);

//    debug(), "euler ", range(euler+1, euler+clk+1);
//    debug(), "depths ", range(depth+1, depth+n);

    build(1, 1, clk);

//    cerr<<clk<<endl;

    int q;
    cin>>q;
    for(int i = 0; i<q; i++){
        int e;
        cin>>e;

        update(1, 1, clk, ranges[e].first, ranges[e].second);

        cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

    }

    return 0;
}
/*
9
2 7 0
1 5 0
6 8 0
4 9 0
2 5 1
7 8 0
2 3 1
4 2 0
0

4
1 2 1
2 3 0
3 4 0
0

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

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 1e6+10;
///===========================================  template  =======================================================

vector<pair<int, int>> adj[nmax];

int depth[nmax];
int edge[nmax];
int pathDepth[nmax];
int clk = 0, euler[nmax];
pair<int, int> ranges[nmax];

void dfs(int u, int par, int e){
    depth[u] = (par == -1)? 1 : depth[par] + 1;
    pathDepth[u] = (par == -1)? 0 : (pathDepth[par] ^ e);

    euler[++clk] = u;
    int last = clk;
    for(auto p : adj[u]){
        if(p.first == par) continue;
        dfs(p.first, u, edge[p.second]);
        euler[++clk] = u;

        ranges[p.second] = {last+1, clk-1};
        last = clk;
    }
    return;
}

#define lc (id<<1)
#define rc ((id<<1)|1)

struct node{
    int m;
    int l_r[2], lm[2], mr[2], lmr[2];
};

inline void op(node &a, int x, node &b, int y, node &c){

    for(int z = 0; z<2; z++){
        int za = z^x, zb = z^y;

        c.lmr[z] = max({a.lm[za] + b.l_r[zb], a.l_r[za] + b.mr[zb], a.lmr[za], b.lmr[zb]});
        c.lm[z] = max({a.l_r[za] - 2*b.m, a.lm[za], b.lm[zb]});
        c.mr[z] = max({b.l_r[zb] - 2*a.m, a.mr[za], b.mr[zb]});
        c.l_r[z] = max({a.l_r[za], b.l_r[zb]});
    }

    c.m = min(a.m, b.m);
}

node tree[4*nmax];
int flip[nmax];

void build(int id, int l, int r)
{
    assert(id < 4*nmax);
    if(l == r)
    {
        int u = euler[l];
        tree[id].m = depth[u];
        tree[id].l_r[pathDepth[u]] = depth[u];
        tree[id].l_r[pathDepth[u]^1] = -1e8;
        tree[id].lm[pathDepth[u]] = -depth[u];
        tree[id].lm[pathDepth[u]^1] = -1e8;
        tree[id].mr[pathDepth[u]] = -depth[u];
        tree[id].mr[pathDepth[u]^1] = -1e8;
        tree[id].lmr[pathDepth[u]] = 0;
        tree[id].lmr[pathDepth[u]^1] = -1e8;
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

void update(int id, int l, int r, int L, int R)
{
    assert(id < 4*nmax);
    if(L <= l && r <= R){
        flip[id] ^= 1;
        return;
    }

    if(r < L || R < l){
        return;
    }

    int mid = (l+r)/2;
    update(lc, l, mid, L, R);
    update(rc, mid+1, r, L, R);

    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 1; i<=n-1; i++){
        int u, v, x;
        cin>>u>>v>>x;
        adj[u].emplace_back(v, i);
        adj[v].emplace_back(u, i);
        edge[i] = x;
    }

    dfs(1, -1, 0);

//    debug(), "euler ", range(euler+1, euler+clk+1);
//    debug(), "depths ", range(depth+1, depth+n);

    build(1, 1, clk);

    cerr<<clk<<endl;

//    cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

//    debug(), dbg(tree[5].lm[1]);

    int q;
    cin>>q;
    for(int i = 0; i<q; i++){
        int e;
        cin>>e;

        update(1, 1, clk, ranges[e].first, ranges[e].second);

        cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

    }

    return 0;
}
/*
9
2 7 0
1 5 0
6 8 0
4 9 0
2 5 1
7 8 0
2 3 1
4 2 0
0

4
1 2 1
2 3 0
3 4 0
0

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

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 1e6+10;
///===========================================  template  =======================================================

vector<pair<int, int>> adj[nmax];

int depth[nmax];
int edge[nmax];
int pathDepth[nmax];
int clk = 0, euler[nmax];
pair<int, int> ranges[nmax];

void dfs(int u, int par, int e){
    depth[u] = (par == -1)? 1 : depth[par] + 1;
    pathDepth[u] = (par == -1)? 0 : (pathDepth[par] ^ e);

    euler[++clk] = u;
    int last = clk;
    for(auto p : adj[u]){
        if(p.first == par) continue;
        dfs(p.first, u, edge[p.second]);
        euler[++clk] = u;

        ranges[p.second] = {last+1, clk-1};
        last = clk;
    }
    return;
}

#define lc (id<<1)
#define rc ((id<<1)|1)

struct node{
    int m;
    int l_r[2], lm[2], mr[2], lmr[2];
};

inline void op(node &a, int x, node &b, int y, node &c){

    for(int z = 0; z<2; z++){
        int za = z^x, zb = z^y;

        c.lmr[z] = max({a.lm[za] + b.l_r[zb], a.l_r[za] + b.mr[zb], a.lmr[za], b.lmr[zb]});
        c.lm[z] = max({a.l_r[za] - 2*b.m, a.lm[za], b.lm[zb]});
        c.mr[z] = max({b.l_r[zb] - 2*a.m, a.mr[za], b.mr[zb]});
        c.l_r[z] = max({a.l_r[za], b.l_r[zb]});
    }

    c.m = min(a.m, b.m);
}

node tree[4*nmax];
int flip[nmax];

void build(int id, int l, int r)
{
    assert(id < 4*nmax);
    if(l == r)
    {
        int u = euler[l];
        tree[id].m = depth[u];
        tree[id].l_r[pathDepth[u]] = depth[u];
        tree[id].l_r[pathDepth[u]^1] = -1e8;
        tree[id].lm[pathDepth[u]] = -depth[u];
        tree[id].lm[pathDepth[u]^1] = -1e8;
        tree[id].mr[pathDepth[u]] = -depth[u];
        tree[id].mr[pathDepth[u]^1] = -1e8;
        tree[id].lmr[pathDepth[u]] = 0;
        tree[id].lmr[pathDepth[u]^1] = -1e8;
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

void update(int id, int l, int r, int L, int R)
{
    assert(id < 4*nmax);
    if(L <= l && r <= R){
        flip[id] ^= 1;
        return;
    }

    if(r < L || R < l){
        return;
    }

    int mid = (l+r)/2;
    update(lc, l, mid, L, R);
    update(rc, mid+1, r, L, R);

    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 1; i<=n-1; i++){
        int u, v, x;
        cin>>u>>v>>x;
        adj[u].emplace_back(v, i);
        adj[v].emplace_back(u, i);
        edge[i] = x;
    }

    dfs(1, -1, 0);

    if(n == 500000){
        cout<<"hoise";
    }

    assert(clk < nmax);

//    debug(), "euler ", range(euler+1, euler+clk+1);
//    debug(), "depths ", range(depth+1, depth+n);

    build(1, 1, clk);

//    cerr<<clk<<endl;

    int q;
    cin>>q;
    for(int i = 0; i<q; i++){
        int e;
        cin>>e;

        update(1, 1, clk, ranges[e].first, ranges[e].second);

        cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

    }

    return 0;
}
/*
9
2 7 0
1 5 0
6 8 0
4 9 0
2 5 1
7 8 0
2 3 1
4 2 0
0

4
1 2 1
2 3 0
3 4 0
0

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

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 1e6+10;
///===========================================  template  =======================================================

vector<pair<int, int>> adj[nmax];

int depth[nmax];
int edge[nmax];
int pathDepth[nmax];
int clk = 0, euler[nmax];
pair<int, int> ranges[nmax];

void dfs(int u, int par, int e){
    depth[u] = (par == -1)? 1 : depth[par] + 1;
    pathDepth[u] = (par == -1)? 0 : (pathDepth[par] ^ e);

    euler[++clk] = u;
    int last = clk;
    for(auto p : adj[u]){
        if(p.first == par) continue;
        dfs(p.first, u, edge[p.second]);
        euler[++clk] = u;

        ranges[p.second] = {last+1, clk-1};
        last = clk;
    }
    return;
}

#define lc (id<<1)
#define rc ((id<<1)|1)

struct node{
    int m;
    int l_r[2], lm[2], mr[2], lmr[2];
};

inline void op(node &a, int x, node &b, int y, node &c){

    for(int z = 0; z<2; z++){
        int za = z^x, zb = z^y;

        c.lmr[z] = max({a.lm[za] + b.l_r[zb], a.l_r[za] + b.mr[zb], a.lmr[za], b.lmr[zb]});
        c.lm[z] = max({a.l_r[za] - 2*b.m, a.lm[za], b.lm[zb]});
        c.mr[z] = max({b.l_r[zb] - 2*a.m, a.mr[za], b.mr[zb]});
        c.l_r[z] = max({a.l_r[za], b.l_r[zb]});
    }

    c.m = min(a.m, b.m);
}

node tree[4*nmax];
int flip[nmax];

void build(int id, int l, int r)
{
    assert(id < 4*nmax);
    if(l == r)
    {
        int u = euler[l];
        tree[id].m = depth[u];
        tree[id].l_r[pathDepth[u]] = depth[u];
        tree[id].l_r[pathDepth[u]^1] = -1e8;
        tree[id].lm[pathDepth[u]] = -depth[u];
        tree[id].lm[pathDepth[u]^1] = -1e8;
        tree[id].mr[pathDepth[u]] = -depth[u];
        tree[id].mr[pathDepth[u]^1] = -1e8;
        tree[id].lmr[pathDepth[u]] = 0;
        tree[id].lmr[pathDepth[u]^1] = -1e8;
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

void update(int id, int l, int r, int L, int R)
{
    assert(id < 4*nmax);
    if(L <= l && r <= R){
        flip[id] ^= 1;
        return;
    }

    if(r < L || R < l){
        return;
    }

    int mid = (l+r)/2;
    update(lc, l, mid, L, R);
    update(rc, mid+1, r, L, R);

    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 1; i<=n-1; i++){
        int u, v, x;
        cin>>u>>v>>x;
        adj[u].emplace_back(v, i);
        adj[v].emplace_back(u, i);
        edge[i] = x;
    }

    dfs(1, -1, 0);

//    debug(), "euler ", range(euler+1, euler+clk+1);
//    debug(), "depths ", range(depth+1, depth+n);

    build(1, 1, clk);

//    cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

//    debug(), dbg(tree[5].lm[1]);

    int q;
    cin>>q;
    for(int i = 0; i<q; i++){
        int e;
        cin>>e;

        update(1, 1, clk, ranges[e].first, ranges[e].second);

        cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

//        debug(), dbg(tree[2].lm[1]);
    }

    return 0;
}
/*
9
2 7 0
1 5 0
6 8 0
4 9 0
2 5 1
7 8 0
2 3 1
4 2 0
0

4
1 2 1
2 3 0
3 4 0
0

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

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 1e6+10;
///===========================================  template  =======================================================

vector<pair<int, int>> adj[nmax];

int depth[nmax];
int edge[nmax];
int pathDepth[nmax];
int clk = 0, euler[nmax];
pair<int, int> ranges[nmax];

void dfs(int u, int par, int e){
    depth[u] = (par == -1)? 1 : depth[par] + 1;
    pathDepth[u] = (par == -1)? 0 : (pathDepth[par] ^ e);

    euler[++clk] = u;
    int last = clk;
    for(auto p : adj[u]){
        if(p.first == par) continue;
        dfs(p.first, u, edge[p.second]);
        euler[++clk] = u;

        ranges[p.second] = {last+1, clk-1};
        last = clk;
    }
    return;
}

#define lc (id<<1)
#define rc ((id<<1)|1)

struct node{
    int m;
    int l_r[2], lm[2], mr[2], lmr[2];
};

inline void op(node &a, int x, node &b, int y, node &c){

    for(int z = 0; z<2; z++){
        int za = z^x, zb = z^y;

//        if(b.l_r[zb] == -1e8){
//            c.lmr[z] = a.lmr[za], c.lm[z] = a.lm[za], c.mr[z] = a.mr[za], c.l_r[z] = a.l_r[za];
//            continue;
//        }
//        if(a.l_r[za] == -1e8){
//            c.lmr[z] = b.lmr[zb], c.lm[z] = a.lm[zb], c.mr[z] = a.mr[zb], c.l_r[z] = b.l_r[zb];
//            continue;
//        }

        c.lmr[z] = max({a.lm[za] + b.l_r[zb], a.l_r[za] + b.mr[zb], a.lmr[za], b.lmr[zb]});
        c.lm[z] = max({a.l_r[za] - 2*b.m, a.lm[za], b.lm[zb]});
        c.mr[z] = max({b.l_r[zb] - 2*a.m, a.mr[za], b.mr[zb]});
        c.l_r[z] = max({a.l_r[za], b.l_r[zb]});
    }

    c.m = min(a.m, b.m);
}

node tree[4*nmax];
int flip[nmax];

void build(int id, int l, int r)
{
    if(l == r)
    {
        int u = euler[l];
        tree[id].m = depth[u];
        tree[id].l_r[pathDepth[u]] = depth[u];
        tree[id].l_r[pathDepth[u]^1] = -1e8;
        tree[id].lm[pathDepth[u]] = -depth[u];
        tree[id].lm[pathDepth[u]^1] = -1e8;
        tree[id].mr[pathDepth[u]] = -depth[u];
        tree[id].mr[pathDepth[u]^1] = -1e8;
        tree[id].lmr[pathDepth[u]] = 0;
        tree[id].lmr[pathDepth[u]^1] = -1e8;
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

void update(int id, int l, int r, int L, int R)
{
    if(L <= l && r <= R){
        flip[id] ^= 1;
        return;
    }

    if(r < L || R < l){
        return;
    }

    int mid = (l+r)/2;
    update(lc, l, mid, L, R);
    update(rc, mid+1, r, L, R);

    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 1; i<=n-1; i++){
        int u, v, x;
        cin>>u>>v>>x;
        adj[u].emplace_back(v, i);
        adj[v].emplace_back(u, i);
        edge[i] = x;
    }

    dfs(1, -1, 0);

//    debug(), "euler ", range(euler+1, euler+clk+1);
//    debug(), "depths ", range(depth+1, depth+n);

    build(1, 1, clk);

//    cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

//    debug(), dbg(tree[5].lm[1]);

    int q;
    cin>>q;
    for(int i = 0; i<q; i++){
        int e;
        cin>>e;

        update(1, 1, clk, ranges[e].first, ranges[e].second);

        cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

//        debug(), dbg(tree[2].lm[1]);
    }

    return 0;
}
/*
9
2 7 0
1 5 0
6 8 0
4 9 0
2 5 1
7 8 0
2 3 1
4 2 0
0

4
1 2 1
2 3 0
3 4 0
0

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

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 2e6+10;
///===========================================  template  =======================================================

vector<pair<int, int>> adj[nmax];

int depth[nmax];
int edge[nmax];
int pathDepth[nmax];
int clk = 0, euler[nmax];
pair<int, int> ranges[nmax];

void dfs(int u, int par, int e){
    depth[u] = (par == -1)? 1 : depth[par] + 1;
    pathDepth[u] = (par == -1)? 0 : (pathDepth[par] ^ e);

    euler[++clk] = u;
    int last = clk;
    for(auto p : adj[u]){
        if(p.first == par) continue;
        dfs(p.first, u, edge[p.second]);
        euler[++clk] = u;

        ranges[p.second] = {last+1, clk-1};
        last = clk;
    }
    return;
}

#define lc (id<<1)
#define rc ((id<<1)|1)

struct node{
    int m;
    int l_r[2], lm[2], mr[2], lmr[2];
};

inline void op(node &a, int x, node &b, int y, node &c){

    for(int z = 0; z<2; z++){
        int za = z^x, zb = z^y;

        c.lmr[z] = max({a.lm[za] + b.l_r[zb], a.l_r[za] + b.mr[zb], a.lmr[za], b.lmr[zb]});
        c.lm[z] = max({a.l_r[za] - 2*b.m, a.lm[za], b.lm[zb]});
        c.mr[z] = max({b.l_r[zb] - 2*a.m, a.mr[za], b.mr[zb]});
        c.l_r[z] = max({a.l_r[za], b.l_r[zb]});
    }

    c.m = min(a.m, b.m);
}

node tree[4*nmax];
int flip[nmax];

void build(int id, int l, int r)
{
    assert(id < 4*nmax);
    if(l == r)
    {
        int u = euler[l];
        tree[id].m = depth[u];
        tree[id].l_r[pathDepth[u]] = depth[u];
        tree[id].l_r[pathDepth[u]^1] = -1e8;
        tree[id].lm[pathDepth[u]] = -depth[u];
        tree[id].lm[pathDepth[u]^1] = -1e8;
        tree[id].mr[pathDepth[u]] = -depth[u];
        tree[id].mr[pathDepth[u]^1] = -1e8;
        tree[id].lmr[pathDepth[u]] = 0;
        tree[id].lmr[pathDepth[u]^1] = -1e8;
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

void update(int id, int l, int r, int L, int R)
{
    assert(id < 4*nmax);
    if(L <= l && r <= R){
        flip[id] ^= 1;
        return;
    }

    if(r < L || R < l){
        return;
    }

    int mid = (l+r)/2;
    update(lc, l, mid, L, R);
    update(rc, mid+1, r, L, R);

    op(tree[lc], flip[lc], tree[rc], flip[rc], tree[id]);
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 1; i<=n-1; i++){
        int u, v, x;
        cin>>u>>v>>x;
        adj[u].emplace_back(v, i);
        adj[v].emplace_back(u, i);
        edge[i] = x;
    }

    dfs(1, -1, 0);

//    debug(), "euler ", range(euler+1, euler+clk+1);
//    debug(), "depths ", range(depth+1, depth+n);

    build(1, 1, clk);

//    cerr<<clk<<endl;

    int q;
    cin>>q;
    for(int i = 0; i<q; i++){
        int e;
        cin>>e;

        update(1, 1, clk, ranges[e].first, ranges[e].second);

        cout<<max(tree[1].lmr[0], tree[1].lmr[1])<<"\n";

    }

    return 0;
}
/*
9
2 7 0
1 5 0
6 8 0
4 9 0
2 5 1
7 8 0
2 3 1
4 2 0
0

4
1 2 1
2 3 0
3 4 0
0

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

*/


#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <set>
#include <map>
#include <cmath>

using namespace std;

typedef long long ll;

const int N = 500000;

int s[N], t[N], type[N];
int q, qind[N];

void dfs(int n,
         vector<vector<int>> & adj,
         int root,
         void preVisit(int, int) = 0,
         void postVisit(int, int) = 0,
         void traverseTreeEdge(int, int, int) = 0,
         void traverseBackEdge(int, int) = 0)
{
    vector<int> parent(n, -2);
    vector<int> stackNode(n);
    vector<int> stackEdgeIndex(n);
    int stackSize = 1;
    stackNode[0] = root;
    stackEdgeIndex[0] = 0;
    parent[root] = -1;

    while (stackSize > 0) {
        int node = stackNode[stackSize - 1];
        int edgeIndex = stackEdgeIndex[stackSize - 1];

        if (edgeIndex == 0 && preVisit) {
            preVisit(node, parent[node]);
        }

        if (edgeIndex == adj[node].size()) {
            stackSize--;

            if (postVisit) {
                postVisit(node, parent[node]);
            }
        }
        else {
            int e = adj[node][edgeIndex];
            int other = s[e] == node ? t[e] : s[e];
            stackEdgeIndex[stackSize - 1]++;

            if (parent[other] == -2) {
                parent[other] = node;
                if (traverseTreeEdge)
                    traverseTreeEdge(node, other, e);
                stackNode[stackSize] = other;
                stackEdgeIndex[stackSize] = 0;
                stackSize++;
            }
            else if (other != parent[node]) {
                if (traverseBackEdge)
                    traverseBackEdge(node, other);
            }
        }
    }
}

int depth[N];
bool good[N];
int preorder[N], postorder[N];
int subtreeRoot[N];
int curorder;

void preVisit(int v, int p) {
    preorder[v] = curorder++;
    if (p == -1) {
        depth[v] = 0;
        good[v] = true;
    }
    else {
        depth[v] = depth[p] + 1;
    }
}

void postVisit(int v, int p) {
    postorder[v] = curorder - 1;
}

void traverseTreeEdge(int p, int v, int e) {
    if (type[e]) good[v] = !good[p];
    else good[v] = good[p];
    subtreeRoot[e] = v;
}

int getFurthest(int n, vector<vector<int>> & adj, int root) {
    dfs(n, adj, root, preVisit);
    int ans = 0;
    for (int i = 1; i < n; i++)
        if (depth[i] > depth[ans]) ans = i;
    return ans;
}

int ans[N];

struct Node
{
    Node * left = 0;
    Node * right = 0;
    int leftValue;
    int rightValue;
    bool inverted = false;
    int goodDepth = 0, badDepth = 0;
};

class SegmentTree
{
public:
    SegmentTree(int n)
    {
        root = buildTree(0, n - 1);
    }

    ~SegmentTree()
    {
        dispose(root);
    }

    void dispose(Node * node)
    {
        if (!node) return;
        dispose(node->left);
        dispose(node->right);
        delete node;
    }

    Node * buildTree(int l, int r)
    {
        Node * node = new Node();
        node->leftValue = l;
        node->rightValue = r;
        if (l < r)
        {
            int mid = (l + r) / 2;
            node->left = buildTree(l, mid);
            node->right = buildTree(mid + 1, r);
        }
        return node;
    }

    void setDepth(int ind, int depth, bool good) {
        setDepth(root, ind, depth, good);
    }

    void setDepth(Node * node, int ind, int depth, bool good) {
        if (node->rightValue == ind && node->leftValue == ind) {
            if (good) node->goodDepth = depth;
            else node->badDepth = depth;
            return;
        }
        if (ind <= node->left->rightValue) setDepth(node->left, ind, depth, good);
        else setDepth(node->right, ind, depth, good);
        node->goodDepth = max(node->left->goodDepth, node->right->goodDepth);
        node->badDepth = max(node->left->badDepth, node->right->badDepth);
    }

    void addSegment(int left, int right)
    {
        addSegment(root, left, right);
    }

    void pushLazy(Node * node)
    {
        if (node->inverted)
        {
            swap(node->goodDepth, node->badDepth);
            if (node->left) node->left->inverted = !node->left->inverted;
            if (node->right) node->right->inverted = !node->right->inverted;
            node->inverted = false;
        }
    }

    void addSegment(Node * node, int left, int right)
    {
        if (node->rightValue < left || node->leftValue > right) return;
        if (left <= node->leftValue && right >= node->rightValue)
        {
            node->inverted = !node->inverted;
            return;
        }
        pushLazy(node);
        addSegment(node->left, left, right);
        addSegment(node->right, left, right);
        node->goodDepth = node->badDepth = 0;
        if (node->left)
        {
            pushLazy(node->left);
            node->goodDepth = node->left->goodDepth;
            node->badDepth = node->left->badDepth;
        }
        if (node->right)
        {
            pushLazy(node->right);
            node->goodDepth = max(node->goodDepth, node->right->goodDepth);
            node->badDepth = max(node->badDepth, node->right->badDepth);
        }
    }

    int query(int left, int right)
    {
        return query(root, left, right);
    }

    int query(Node * node, int left, int right)
    {
        if (!node || node->rightValue < left || node->leftValue > right) return 0;
        pushLazy(node);
        if (left <= node->leftValue && right >= node->rightValue)
        {
            return node->goodDepth;
        }
        return max(query(node->left, left, right), query(node->right, left, right));
    }

    Node * root;
};

void solve(int n, vector<vector<int>> & adj, int root) {
    //cout << "From " << root << "\n";
    curorder = 0;
    dfs(n, adj, root, preVisit, postVisit, traverseTreeEdge);
    //for (int i = 0; i < n; i++) cout << preorder[i] << " " << postorder[i] << "\n";
    SegmentTree tree(n);
    for (int i = 0; i < n; i++) tree.setDepth(preorder[i], depth[i], good[i]);
    for (int i = 0; i < q; i++) {
        int v = subtreeRoot[qind[i]];
        //cout << "Edge " << qind[i] << " subroot " << v << "\n";
        tree.addSegment(preorder[v], postorder[v]);
        ans[i] = max(ans[i], tree.query(0, n - 1));
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    vector<vector<int>> adj(n);
    for (int i = 0; i < n - 1; i++) {
        cin >> s[i] >> t[i] >> type[i];
        s[i]--; t[i]--;
        adj[s[i]].push_back(i);
        adj[t[i]].push_back(i);
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> qind[i]; qind[i]--;
    }
    int v1 = getFurthest(n, adj, 0);
    int v2 = getFurthest(n, adj, v1);
    memset(ans, 0, sizeof(ans));
    solve(n, adj, v1);
    solve(n, adj, v2);
    for (int i = 0; i < q; i++) cout << ans[i] << "\n";
    return 0;
}


#include <bits/stdc++.h>
#define lson(v) v << 1
#define rson(v) v << 1 | 1
using namespace std;

const int maxn = 5e5 + 10;
pair<int,int> edges[maxn];
vector<pair<int,int>> g[maxn];
int n, m;
int opt[maxn];
int dep[maxn];

int dfs(int o,int p) {
    dep[o] = dep[p] + 1;
    int res = o;
    for(auto u : g[o]) if(u.first != p) {
        int tmp = dfs(u.first, o);
        if(dep[res] < dep[tmp]) res = tmp;
    }
    return res;
}
int dfn[maxn],efn[maxn],rdfn[maxn],col[maxn],tot;
void dfs1(int o,int p,int s) {

    dfn[o] = ++tot;
    rdfn[tot] = o;
    col[o] = s;
    for(auto u : g[o]) if(u.first != p) {
        dfs1(u.first, o, s^u.second);
    }
    efn[o] = tot;
//    printf("%d %d %d\n", o, dfn[o], efn[o]);
}
int seg[maxn << 2][2];
int flip[maxn << 2];

int get_val(int v, int d) {
    return seg[v][d^flip[v]];
}

void pushdown(int v) {
    if(flip[v]) {
        swap(seg[v][0], seg[v][1]);
        flip[lson(v)] ^= 1;
        flip[rson(v)] ^= 1;
        flip[v] = 0;
    }
}

void pushup(int v) {
    seg[v][0] = max(get_val(lson(v), 0), get_val(rson(v), 0));
    seg[v][1] = max(get_val(lson(v), 1), get_val(rson(v), 1));
}
void build(int l, int r,int v) {
    seg[v][0] = seg[v][1] = 0;
    flip[v] = 0;
    if(l == r) {
        seg[v][col[rdfn[l]]] = dep[rdfn[l]];
        return;
    }
    int mid = (l + r) >> 1;
    build(l, mid, lson(v));
    build(mid + 1, r, rson(v));
    pushup(v);
}
void update(int l,int r,int v, int ql,int qr) {
    if(ql <= l&&r <= qr) {
        flip[v] ^= 1;
        return;
    }
    pushdown(v);
    int mid = (l + r) >> 1;
    if(ql <= mid) update(l, mid, lson(v), ql, qr);
    if(qr > mid) update(mid + 1, r, rson(v), ql, qr);
    pushup(v);
}

void solve(int root, int* ans) {
    tot = 0;
    dfs(root, 0);
    dfs1(root, 0, 0);
    build(1, n, 1);
    for(int i = 1;i <= m;++i) {
        int x = opt[i];
        int l = max(dfn[edges[x].first], dfn[edges[x].second]);
        int r = min(efn[edges[x].first], efn[edges[x].second]);
//        printf("%d %d\n", l, r);
        update(1, n, 1, l, r);
//        for(int j = 1;j <= 9;++j) printf("%d %d %d\n", seg[j][0], seg[j][1], flip[j]);
        ans[i] = get_val(1, 0);
    }
//    for(int i = 1;i <= m;++i) printf("%d ",ans[i]);puts("");
}
int ans1[maxn], ans2[maxn];
int main() {
    scanf("%d", &n);
    for(int i = 1;i < n;++i) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        edges[i] = make_pair(a, b);
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }
    int root1 = dfs(1, 0);
    int root2 = dfs(root1, 0);
    scanf("%d", &m);
    for(int i = 1;i <= m;++i) scanf("%d", &opt[i]);
    solve(root1, ans1);
    solve(root2, ans2);
    for(int i = 1;i <= m;++i) printf("%d\n", max(ans1[i], ans2[i])-1);
    return 0;
}


#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 5e5 + 7;

int yes[N];
V<pi> G[N];

pi farthest(int u, int p = -1) {
	pi ans = {0, u};
	for(pi e:G[u]) if(e.F != p) {
		pi tt = farthest(e.F, u);
		tt.F++;
		ans = max(ans, tt);
	}
	return ans;
}

int n;

struct seg {
	/*
	    NOTE: remember to call build function
	*/
	struct T {
		bool flip;
		int ans0, ans1;
		T(int val = 0) {
			flip = 0;
			ans0 = val;
			ans1 = 0;
		}
	};

	T t[N * 4];
	int a[N];

	inline T add(T x, T y) {
		T z;
		z.ans0 = max(x.ans0, y.ans0);
		z.ans1 = max(x.ans1, y.ans1);
		return z;
	}

	inline void pull(int v) {
		t[v] = add(t[v * 2], t[v * 2 + 1]);
	}

	inline void apply(int v) {
		t[v].flip ^= 1;
		swap(t[v].ans0, t[v].ans1);
	}

	inline void push(int v) {
		if(t[v].flip) {
			apply(v * 2);
			apply(v * 2 + 1);
			t[v].flip = 0;
		}
	}

	void build(int v = 1, int tl = 0, int tr = n) {
		if(tr - tl == 1) {
			t[v] = T(a[tl]); // set one
			return;
		}
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm, tr);
		pull(v);
	}
	void upd(int l, int r, int v = 1, int tl = 0, int tr = n) {
		if(l <= tl && tr <= r) {
			apply(v);
			return;
		}
		push(v);
		int tm = (tl + tr) / 2;
		if(l < tm) upd(l, r, v * 2, tl, tm);
		if(r > tm) upd(l, r, v * 2 + 1, tm, tr);
		pull(v);
	}

};

struct DS {
	int tin[N], tout[N], down[N], tm;
	seg t;
	void dfs(int u, int p = -1, int depth = 0) {
		tin[u] = tm++;
		t.a[tin[u]] = depth;
		for(pi e:G[u]) if(e.F != p) {
			int v = e.F, id = e.S;
			down[id] = v;
			dfs(v, u, depth + 1);
		}
		tout[u] = tm;
	}
	DS(int root) {
		tm = 0;
		dfs(root);
		t.build();
	}
	void flip(int edge) {
		int u = down[edge];
		t.upd(tin[u], tout[u]);
	}
	int qry() {
		return t.t[1].ans0;
	}
};

signed main()
{
	IO_OP;

	cin >> n;
	for(int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v >> yes[i];
		G[u].EB(v, i);
		G[v].EB(u, i);
	}
	int r1 = farthest(1).S, r2 = farthest(r1).S;

	DS d1(r1), d2(r2);
	auto flip = [&](int edge) {
		d1.flip(edge);
		d2.flip(edge);
	};

	for(int i = 0; i < n - 1; i++)
		if(yes[i]) flip(i);
	int m;
	cin >> m;
	while(m--) {
		int i;
		cin >> i;
		i--;
		flip(i);
		cout << max(d1.qry(), d2.qry()) << '\n';
	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
const int N = 1000006;
using namespace std;

char s[N];
int num[10];
int main(){
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i < len; i++){
		num[s[i]-'0']++;
	}
	num[1]--;
	num[6]--;
	num[8]--;
	num[9]--;
	int ans = 1;
	for(int i = 1; i <= 9; i++){
		if(num[i]==0) continue;
		ans*=i;
		num[i]--;
		ans %= 7;
		printf("i");
	}
	ans*=10000;
	ans%=7;
	switch(ans){
		case 0: printf("1869");break;
		case 1: printf("1968");break;
		case 2: printf("1689");break;
		case 3: printf("6891");break;
		case 4: printf("1698");break;
		case 5: printf("1986");break;
		case 6: printf("1896");break;
	}
	while(num[0]) printf("0");
	puts("");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
const int N = 1000006;
using namespace std;

char s[N];
int num[10];
int main(){
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i < len; i++){
		num[s[i]-'0']++;
	}
	num[1]--;
	num[6]--;
	num[8]--;
	num[9]--;
	LL ans = 0;
	for(int i = 1; i <= 9; i++){
		while(num[i]){
            ans*=10;
            ans+=i;
            num[i]--;
            ans %= 7;
            printf("%d", i);
		}
	}
	ans*=10000;
	ans%=7;
	//cout<<1986%7<<endl;
	switch(ans){
		case 0: printf("1869");break;
		case 6: printf("1968");break;
		case 5: printf("1689");break;
		case 4: printf("6891");break;
		case 3: printf("1698");break;
		case 2: printf("1986");break;
		case 1: printf("1896");break;
	}
	while(num[0]){
        printf("0"),num[0]--;
	}
	puts("");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
const int N = 1000006;
using namespace std;

char s[N];
int num[10];
int main(){
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i < len; i++){
		num[s[i]-'0']++;
	}
	num[1]--;
	num[6]--;
	num[8]--;
	num[9]--;
	int ans = 1;
	bool flag = 0;
	for(int i = 1; i <= num[i]; i++){
		printf("1");
	}
	for(int i = 2; i <= 9; i++){
		if(num[i]==0) continue;
        flag = 1;
		ans*=i;
		num[i]--;
		ans %= 7;
		printf("%d", i);
	}
	ans*=10000;
	ans%=7;
	if(!flag) ans = 0;
	switch(ans){
		case 0: printf("1869");break;
		case 1: printf("1968");break;
		case 2: printf("1689");break;
		case 3: printf("6891");break;
		case 4: printf("1698");break;
		case 5: printf("1986");break;
		case 6: printf("1896");break;
	}
	while(num[0]) printf("0"),num[0]--;
	puts("");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
const int N = 1000006;
using namespace std;

char s[N];
int num[10];
int main(){
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i < len; i++){
		num[s[i]-'0']++;
	}
	num[1]--;
	num[6]--;
	num[8]--;
	num[9]--;
	int ans = 1;
	bool flag = 0;
	for(int i = 1; i <= 9; i++){
		if(num[i]==0) continue;
        flag = 1;
		ans*=i;
		num[i]--;
		ans %= 7;
		printf("i");
	}
	ans*=10000;
	ans%=7;
	if(!flag) ans = 0;
	switch(ans){
		case 0: printf("1869");break;
		case 1: printf("1968");break;
		case 2: printf("1689");break;
		case 3: printf("6891");break;
		case 4: printf("1698");break;
		case 5: printf("1986");break;
		case 6: printf("1896");break;
	}
	while(num[0]) printf("0");
	puts("");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
const int N = 1000006;
using namespace std;

char s[N];
int num[10];
int main(){
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i < len; i++){
		num[s[i]-'0']++;
	}
	num[1]--;
	num[6]--;
	num[8]--;
	num[9]--;
	int ans = 1;
	bool flag = 0;
	for(int i = 1; i <= num[i]; i++){
		printf("1");
	}
	for(int i = 2; i <= 9; i++){
		while(num[i]){
            flag = 1;
            ans*=i;
            num[i]--;
            ans %= 7;
            printf("%d", i);
		}
	}
	ans*=10000;
	ans%=7;
	if(!flag) ans = 0;
	switch(ans){
		case 0: printf("1869");break;
		case 1: printf("1968");break;
		case 2: printf("1689");break;
		case 3: printf("6891");break;
		case 4: printf("1698");break;
		case 5: printf("1986");break;
		case 6: printf("1896");break;
	}
	while(num[0]) printf("0"),num[0]--;
	puts("");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
const int N = 1000006;
using namespace std;

char s[N];
int num[10];
int main(){
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i < len; i++){
		num[s[i]-'0']++;
	}
	num[1]--;
	num[6]--;
	num[8]--;
	num[9]--;
	int ans = 1;
	bool flag = 0;
	for(int i = 1; i <= num[i]; i++){
		printf("1");
	}
	for(int i = 2; i <= 9; i++){
		if(num[i]==0) continue;
        flag = 1;
		ans*=i;
		num[i]--;
		ans %= 7;
		printf("i");
	}
	ans*=10000;
	ans%=7;
	if(!flag) ans = 0;
	switch(ans){
		case 0: printf("1869");break;
		case 1: printf("1968");break;
		case 2: printf("1689");break;
		case 3: printf("6891");break;
		case 4: printf("1698");break;
		case 5: printf("1986");break;
		case 6: printf("1896");break;
	}
	while(num[0]) printf("0"),num[0]--;
	puts("");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
const int N = 1000006;
using namespace std;

char s[N];
int num[10];
int main(){
    //LL sum = 1;
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i < len; i++){
		num[s[i]-'0']++;
	}
	num[1]--;
	num[6]--;
	num[8]--;
	num[9]--;
	LL ans = 0;
	//bool flag = 0;
	for(int i = 1; i <= num[i]; i++){
		printf("1");
	}
	for(int i = 2; i <= 9; i++){
		while(num[i]){
            //flag = 1;
            ans*=10;
            ans+=i;
            num[i]--;
            ans %= 7;
            printf("%d", i);
		}
	}
	//cout<<sum<<endl;
	//cout<<(sum*10000)%7<<endl;
	ans*=10000;
	ans%=7;
	//if(!flag) ans = 0;
	switch(ans){
		case 0: printf("1869");break;
		case 1: printf("1968");break;
		case 2: printf("1689");break;
		case 3: printf("6891");break;
		case 4: printf("1698");break;
		case 5: printf("1986");break;
		case 6: printf("1896");break;
	}
	while(num[0]) printf("0"),num[0]--;
	puts("");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
const int N = 1000006;
using namespace std;

char s[N];
int num[10];
int main(){
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i < len; i++){
		num[s[i]-'0']++;
	}
	num[1]--;
	num[6]--;
	num[8]--;
	num[9]--;
	int ans = 1;
	bool flag = 0;
	for(int i = 1; i <= num[i]; i++){
		printf("1");
	}
	for(int i = 2; i <= 9; i++){
		while(num[i]){
            flag = 1;
            ans*=i;
            num[i]--;
            ans %= 7;
            if(ans == 0) ans = 1;
            printf("%d", i);
		}
	}
	ans*=10000;
	ans%=7;
	if(!flag) ans = 0;
	switch(ans){
		case 0: printf("1869");break;
		case 1: printf("1968");break;
		case 2: printf("1689");break;
		case 3: printf("6891");break;
		case 4: printf("1698");break;
		case 5: printf("1986");break;
		case 6: printf("1896");break;
	}
	while(num[0]) printf("0"),num[0]--;
	puts("");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using std::string;
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
//#define mod 1000000007
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define EPSILON 1e-9
#define MAX 100002
#define PI 3.1415926535897932384626433832795028841971693993751
typedef long long  ll;
typedef unsigned long long llu;
typedef long double  ldb;
typedef double  db ;
string ans;
int cnt[10];
void string_add(int n)
{
    string t;
    while(n)
    {
        t+=n%10+'0';
        n/=10;
    }
    reverse(t.begin(),t.end());
    ans+=t;
}
void find_string(int mod)
{
    if(mod==0)
        string_add(1869);
    if(mod==1)
        string_add(1968);
    if(mod==2)
        string_add(9186);
    if(mod==3)
        string_add(1689);
    if(mod==4)
        string_add(1698);
    if(mod==5)
        string_add(1986);
    if(mod==6)
        string_add(1896);

}
int main()
{
    //freopen("in.txt","r",stdin);
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.size();i++)
    {
        int n=(s[i]-'0');
        if(n==1&&cnt[1]==0)
       {
           cnt[1]++;
           continue;
       }
        else if(n==6&&cnt[6]==0)
       {
           cnt[6]++;
           continue;
       }
         else if(n==8&&cnt[8]==0)
        {
             cnt[8]++;
            continue;
        }
         else if(n==9&&cnt[9]==0)
        {
             cnt[9]++;
            continue;
        }
         else if(n==0)
        {
             cnt[0]++;
            continue;
        }
         n=c*10+n;
         if(n<7)
         {
             c=n;
             ans+=s[i];
         }
        else if(n>=7)
         {
             c=n%7;
             ans+=s[i];
         }

    }//cout<<"c"<<c<<endl;
    find_string(7-(c*10000)%7);
    while(cnt[0]--)
    {
        ans+='0';
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using std::string;
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
//#define mod 1000000007
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define EPSILON 1e-9
#define MAX 100002
#define PI 3.1415926535897932384626433832795028841971693993751
typedef long long  ll;
typedef unsigned long long llu;
typedef long double  ldb;
typedef double  db ;
string ans;
int cnt[10];
void string_add(int n)
{
    string t;
    while(n)
    {
        t+=n%10+'0';
        n/=10;
    }
    reverse(t.begin(),t.end());
    ans+=t;
}
void find_string(int mod)
{
    if(mod==7)
        string_add(1869);
    if(mod==1)
        string_add(1968);
    if(mod==2)
        string_add(1689);
    if(mod==3)
        string_add(6198);
    if(mod==4)
        string_add(1698);
    if(mod==5)
        string_add(1986);
    if(mod==6)
        string_add(1896);

}
int main()
{
  // freopen("in.txt","r",stdin);
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.size();i++)
    {
        int n=(s[i]-'0');
        if(n==1&&cnt[1]==0)
       {
           cnt[1]++;
           continue;
       }
        else if(n==6&&cnt[6]==0)
       {
           cnt[6]++;
           continue;
       }
         else if(n==8&&cnt[8]==0)
        {
             cnt[8]++;
            continue;
        }
         else if(n==9&&cnt[9]==0)
        {
             cnt[9]++;
            continue;
        }
         else if(n==0)
        {
             cnt[0]++;
            continue;
        }
         n=c*10+n;
         if(n<7)
         {
             c=n;
             ans+=s[i];
         }
        else if(n>=7)
         {
             c=n%7;
             ans+=s[i];
         }

    }//cout<<"c"<<c<<endl;
    find_string(7-((c*10000)%7));
    while(cnt[0]--)
    {
        ans+='0';
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using std::string;
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
//#define mod 1000000007
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define EPSILON 1e-9
#define MAX 100002
#define PI 3.1415926535897932384626433832795028841971693993751
typedef long long  ll;
typedef unsigned long long llu;
typedef long double  ldb;
typedef double  db ;
string ans;
int cnt[10];
void string_add(int n)
{
    string t;
    while(n)
    {
        t+=n%10+'0';
        n/=10;
    }
    reverse(t.begin(),t.end());
    ans+=t;
}
void find_string(int mod)
{
    if(mod==7)
        string_add(1869);
    if(mod==1)
        string_add(1968);
    if(mod==2)
        string_add(9186);
    if(mod==3)
        string_add(1689);
    if(mod==4)
        string_add(1698);
    if(mod==5)
        string_add(1986);
    if(mod==6)
        string_add(1896);

}
int main()
{
   //freopen("in.txt","r",stdin);
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.size();i++)
    {
        int n=(s[i]-'0');
        if(n==1&&cnt[1]==0)
       {
           cnt[1]++;
           continue;
       }
        else if(n==6&&cnt[6]==0)
       {
           cnt[6]++;
           continue;
       }
         else if(n==8&&cnt[8]==0)
        {
             cnt[8]++;
            continue;
        }
         else if(n==9&&cnt[9]==0)
        {
             cnt[9]++;
            continue;
        }
         else if(n==0)
        {
             cnt[0]++;
            continue;
        }
         n=c*10+n;
         if(n<7)
         {
             c=n;
             ans+=s[i];
         }
        else if(n>=7)
         {
             c=n%7;
             ans+=s[i];
         }

    }//cout<<"c"<<c<<endl;
    find_string(7-((c*10000)%7))`;
    while(cnt[0]--)
    {
        ans+='0';
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using std::string;
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
//#define mod 1000000007
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define EPSILON 1e-9
#define MAX 100002
#define PI 3.1415926535897932384626433832795028841971693993751
typedef long long  ll;
typedef unsigned long long llu;
typedef long double  ldb;
typedef double  db ;
string ans;
int cnt[10];
void string_add(int n)
{
    string t;
    while(n)
    {
        t+=n%10+'0';
        n/=10;
    }
    reverse(t.begin(),t.end());
    ans+=t;
}
void find_string(int mod)
{
    if(mod==0)
        string_add(1869);
    if(mod==1)
        string_add(1968);
    if(mod==2)
        string_add(9186);
    if(mod==3)
        string_add(6198);
    if(mod==4)
        string_add(1698);
    if(mod==5)
        string_add(9168);
    if(mod==6)
        string_add(1896);

}
int main()
{
    //freopen("in.txt","r",stdin);
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.size();i++)
    {
        int n=(s[i]-'0');
        if(n==1&&cnt[1]==0)
       {
           cnt[1]++;
           continue;
       }
        else if(n==6&&cnt[6]==0)
       {
           cnt[6]++;
           continue;
       }
         else if(n==8&&cnt[8]==0)
        {
             cnt[8]++;
            continue;
        }
         else if(n==9&&cnt[9]==0)
        {
             cnt[9]++;
            continue;
        }
         else if(n==0)
        {
             cnt[0]++;
            continue;
        }
         n=c*10+n;
         if(n<7)
         {
             c=n;
             ans+=s[i];
         }
        else if(n>=7)
         {
             c=n%7;
             ans+=s[i];
         }

    }
    find_string(c);
    while(cnt[0]--)
    {
        ans+='0';
    }
    cout<<ans<<endl;
}