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


int dist(const vector<set<int>> &gr){
    int n = gr.size();
    vector<int> used(n);
    int st = -1;
    for (int i = 0; i < n; i++)
    {
        if(!gr[i].empty()) {
            st = i; break;
        }
    }
    assert(st != -1);
    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;
    }
    


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

    return used[st]-1;
}



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

    int q;
    cin>>q;
    gr.resize(n+q+1);
    int id = n; 
    int count_ver = n;
    while(q--){
        char c;
        int u;
        cin>>c>>u;
        u--;
        if(c == '+'){
            count_ver++;
            gr[u].insert(id);
            gr[id].insert(u);
            id++;
        }else{
            auto it = *gr[u].begin();
            count_ver--;
            gr[u].erase(it);
            gr[it].erase(u);
        }

        // cout<<2*(count_ver-1)<<'\n';
        cout<<2*(count_ver-1) - dist(gr)<<'\n';
    }

    
}