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


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


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



struct segtree
{
    segtree *l = nullptr, *r = nullptr;
    vector<int> zapr;
    int lb, rb;
    segtree(int lb, int rb):lb(lb), rb(rb){
        int m = (lb+rb)/2;
        if(lb + 1 < rb){
            l = new segtree(lb, m);
            r = new segtree(m, rb);
        }
    }
    void upd(int lq, int rq, int id){

        if(max(lb, lq) >= min(rb, rq)) return;
        if(lq<=lb && rb <= rq) {
            zapr.push_back(id);
            return;
        }
        if(l){
            l->upd(lq, rq, id);
            r->upd(lq, rq, id);
        }
    }

  

    void obhod(int a, int b, int count_ver = 0){

        
        int res = 0;
        if(a != -1) res = get_ans(a, b); 
        for(auto id:zapr){
            count_ver++;
            if(a == -1){
                a = b = id;
            }
            tie(res, a, b) = upd_ans(a, b, id);
        }
        if(l == nullptr) cout<< 2*(count_ver-1) - res<<'\n';
        else{
            l->obhod(a, b, count_ver);
            r->obhod(a, b, count_ver);
        }
    }
};







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;
    segtree sg(0, q);
    edges.resize(n+q+1);
    vector<int> in(n), out(n, q+1);
    int zapr_id = 0;
    for (int i = 0; i < n; i++)
    {
        in[i] = zapr_id;
    }
    for (int i = 0; i < q; i++)
    {
        char c;
        int u;
        cin>>c>>u;
        u--;
        
        if(c == '+'){
            edges.push_back({u, in.size()});
            in.push_back(zapr_id);
            out.push_back(q+1);
        }else{
            out[u] = zapr_id;
        }
        zapr_id++;
    }
    
    
   
    

    for (int i = 0; i < edges.size(); i++)
    {
        auto [x, y] = edges[i];
        
        
        g[x].insert(y);
        g[y].insert(x);
    }

    // auto [a, b] = diam(gr);

    
    dfs(0);

    for (int i = 0; i < in.size(); i++)
    {
        sg.upd(in[i], out[i], i);
    }
    sg.obhod(-1, -1);
    

   
    
    
    
    


    
}