#include<bits/stdc++.h>
using namespace std;
#define pb  push_back
#define ll  long long
#define vi  vector<ll >
#define vvi vector<vi >
#define all(x) x.begin(), x.end()

int n, q;
int rim[2], diam;
vi  d[2], u;
vvi g;
set<int> S;

void dfs(int v, int dep) {
    u[v] = 1;
    d[1][v] = dep;
    if (d[1][v] >= diam) {
        diam = d[1][v];
        rim[1] = v;
    }
    for (int i = 0; i < g[v].size(); ++i) {
        int to = g[v][i];
        if (!u[to])
            dfs(to, dep + 1);
    }
    u[v] = 0;
}

void calc_tree() {
    diam = 0;
    dfs(*S.begin(), 0);
    rim[0] = rim[1];
    dfs(rim[0], 0);
    d[0] = d[1];
    dfs(rim[1], 0);
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    g.resize(n);
    for (int i = 1; i < n; ++i) {
        int a, b; cin >> a >> b; --a; --b;
        g[a].pb(b); g[b].pb(a);
    }
    cin >> q;
    d[0] = d[1] = vi(n + q);
    g.resize(n + q);
    u.assign(n + q, 0);
    for (int i = 0; i < n; ++i)
        S.insert(i);
    char c;
    int  v;
    while (q--) {
        cin >> c >> v; --v;
        if (c == '+') {
            g[v].pb(n); g[n].pb(v);
            S.insert(n); ++n;
            if (d[0][v] < diam && d[1][v] < diam) {
                d[0][n - 1] = d[0][v] + 1;
                d[1][n - 1] = d[1][v] + 1;
            }
            else
                calc_tree();
            cout << 2 * (S.size() - 1) - diam << "\n";
        }
        else {
            u[v] = 1;
            S.erase(v);
            calc_tree();
            cout << 2 * (S.size() - 1) - diam << "\n";
        }
    }

    return 0;
}
