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


const int maxn=1e6+5, logn=30;
 
vector<int> g[maxn];

pair<int, int> diam(const vector<set<int>> &gr){
    int n = maxn;
    vector<int> used(n);
    int st;
    for (int i = 0; i < n; i++)
    {
        if(!gr[i].empty()) {
            st = i; break;
        }
    }
    queue<int> q;

    used = vector<int>(n);
    used[st] = 1;
    q = {};
    q.push(st);
    while(!q.empty()){

        auto it = q.front();
        q.pop();
        
        for(auto i : gr[it]){
            if(used[i]) continue;
            used[i] = used[it] + 1;
            q.push(i);
        }
    }

    for (int i = 0; i < n; i++)
    {
        if(used[st] < used[i]) st = i;
    }
    

    int fir = st;
    
    used = vector<int>(n);
    used[st] = 1;
    q = {};
    q.push(st);
    while(!q.empty()){
        auto it = q.front();
        q.pop();
        for(auto i : gr[it]){
            if(used[i]) continue;
            used[i] = used[it] + 1;
            q.push(i);
        }
    }

    for (int i = 0; i < n; i++)
    {
        if(used[st] < used[i]) st = i;
    }

    int sec = st;


    return {fir, sec};
}

int tout[maxn], tin[maxn], used[maxn], dist[maxn];
int timer=0;
int up[maxn][logn];

 
 
void dfs(int v, int p = 0, int s=0) {
    if(used[v]) return;
    used[v]=1;
    up[v][0] = p;
    tin[v]=timer++;
    dist[v]=s;
    for (int l = 1; l < logn; l++)
        up[v][l] = up[up[v][l-1]][l-1];
    for(auto u:g[v]){
        dfs(u, v, s+1);
    }
    tout[v]=timer++;
}
bool upper(int u, int v) {
    return (tin[u] <= tin[v]) && (tout[u] >= tout[v]);
}
int lca (int v, int u) {
    if (upper(v, u)) return v;
    if (upper(u, v)) return u;
    for (int l = logn-1; l >= 0; l--)
        if (!upper(up[v][l], u))
            v = up[v][l];
    return up[v][0];
}
int get_ans(int a, int b){
    return dist[a]+dist[b]-2*dist[lca(a, b)];
}


tuple<int, int, int> upd_ans(int a, int b, int c){
    // cout<<"dbg: "<<'\n';
    // cout<<"    "<<get_ans(a, b)<<" "<<a<<" "<<b<<'\n';
    // cout<<"    "<<get_ans(b, c)<<" "<<b<<" "<<c<<'\n';
    // cout<<"    "<<get_ans(a, c)<<" "<<a<<" "<<c<<'\n';
    return max<tuple<int, int, int>>({
        {get_ans(a, b), a, b},
        {get_ans(b, c), b, c},
        {get_ans(a, c), a, c}
    });
}






int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<pair<int, int>> edges(n-1);
    for (int i = 0; i < n-1; i++)
    {
        int x, y;
        cin>>x>>y;
        x--;
        y--;
        edges[i] = {x, y};
    }

    int q;
    cin>>q;
    edges.resize(n+q+1);
    int id = n; 
    vector<pair<int, int>> zapr;
    vector<set<int>> gr(n+q);
    while(q--){
        char c;
        int u;
        cin>>c>>u;
        u--;
        
        if(c == '+'){
            edges.push_back({u, id});
            zapr.push_back({u, id});
            id++;
        }else{
            zapr.push_back({-1, -u});
        }
    }


    

    for (int i = 0; i < n-1; i++)
    {
        auto [x, y] = edges[i];
        g[x].push_back(y);
        g[y].push_back(x);
        gr[x].insert(y);
        gr[y].insert(x);
    }

    auto [a, b] = diam(gr);
    for (int i = n-1; i < edges.size(); i++)
    {
        auto [x, y] = edges[i];
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(0);

    int count_ver = n;
    

    for(auto [pr, c] : zapr){
        if(c > 0){
            count_ver++;
            gr[c].insert(pr);
            gr[pr].insert(c);
            auto [res, x, y] = upd_ans(a, b, c);
            // cout<<2 *(count_ver-1)<<'\n';
            cout<<2 *(count_ver-1) - res<<'\n';
            a = x;
            b = y;
        }
        else{
            count_ver--;
            c = -c;
            auto it = *gr[c].begin();
            gr[c].erase(it);
            gr[it].erase(c);
            
            
            auto [x, y] = diam(gr);
           
            // cout<<2 *(count_ver-1)<<'\n';
            cout<<2*(count_ver-1) - get_ans(x, y)<<'\n';
            a = x;
            b = y;
        }
    }
    
    
    
    


    
}