#include <bits/stdc++.h>
using namespace std;
long long int h[100001], par[100001][25], in[100001], out[100001], timer,
    sum[100001];
set<pair<long long int, long long int> > active;
set<pair<long long int, long long int> >::iterator it, it1, it2;
vector<pair<long long int, long long int> > v[100001];
void dfs(long long int cur, long long int p, long long int wt) {
  timer++;
  in[cur] = timer;
  par[cur][0] = p;
  sum[cur] = wt;
  if (p != -1) h[cur] = h[p] + 1;
  for (long long int i = 1; i < 20; i++) {
    if (par[cur][i - 1] != -1) par[cur][i] = par[par[cur][i - 1]][i - 1];
  }
  for (long long int i = 0; i < v[cur].size(); i++) {
    long long int x = v[cur][i].first;
    if (x == p) continue;
    dfs(x, cur, wt + v[cur][i].second);
  }
  out[cur] = timer;
}
int lca(int v, int u) {
  if (h[v] < h[u]) swap(v, u);
  for (int i = 20 - 1; i >= 0; i--) {
    if (par[v][i] != -1 && h[par[v][i]] >= h[u]) {
      v = par[v][i];
    }
  }
  if (v == u) return u;
  for (int i = 20 - 1; i >= 0; i--) {
    if (par[v][i] - par[u][i]) v = par[v][i], u = par[u][i];
  }
  return par[v][0];
}
inline long long int distance(long long int x, long long int y) {
  return sum[x] + sum[y] - 2 * sum[lca(x, y)];
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int cur_sum = 0, i, j, n, x, y, z, q, node, first_node, last_node,
                new_first_node, new_last_node;
  char type;
  memset(par, -1, sizeof par);
  cin >> n;
  for (i = 1; i <= n - 1; i++) {
    cin >> x >> y >> z;
    v[x].push_back(make_pair(y, z));
    v[y].push_back(make_pair(x, z));
  }
  dfs(1, -1, 0);
  cin >> q;
  while (q--) {
    cin >> type;
    if (type == '+') {
      cin >> node;
      if (!active.size()) {
        active.insert(make_pair(in[node], node));
        cur_sum = 0;
        continue;
      }
      if (active.size() == 1) {
        x = (*active.begin()).second;
        cur_sum = 2 * distance(x, node);
        active.insert(make_pair(in[node], node));
        continue;
      }
      first_node = (*active.begin()).second;
      last_node = (*active.rbegin()).second;
      if (in[node] < (*active.begin()).first ||
          in[node] > (*active.rbegin()).first) {
        cur_sum = cur_sum - distance(first_node, last_node);
        cur_sum = cur_sum + distance(node, first_node);
        cur_sum = cur_sum + distance(node, last_node);
        active.insert(make_pair(in[node], node));
        continue;
      }
      it1 = active.upper_bound(make_pair(in[node], -1));
      it2 = it1;
      --it2;
      x = (*it1).second;
      y = (*it2).second;
      cur_sum = cur_sum - distance(x, y);
      cur_sum = cur_sum + distance(x, node);
      cur_sum = cur_sum + distance(y, node);
      active.insert(make_pair(in[node], node));
    } else if (type == '-') {
      cin >> node;
      if (!active.size()) assert(false);
      if (active.size() == 1) {
        active.erase(active.begin());
        cur_sum = 0;
        continue;
      }
      first_node = (*active.begin()).second;
      last_node = (*active.rbegin()).second;
      if (node == first_node) {
        active.erase(active.begin());
        new_first_node = (*active.begin()).second;
        cur_sum = cur_sum - distance(first_node, new_first_node);
        cur_sum = cur_sum - distance(first_node, last_node);
        cur_sum = cur_sum + distance(new_first_node, last_node);
        continue;
      }
      if (node == last_node) {
        active.erase(--active.end());
        new_last_node = (*active.rbegin()).second;
        cur_sum = cur_sum - distance(first_node, last_node);
        cur_sum = cur_sum - distance(last_node, new_last_node);
        cur_sum = cur_sum + distance(new_last_node, first_node);
        continue;
      }
      it = active.find(make_pair(in[node], node));
      assert(it != active.end());
      it1 = it;
      it2 = it;
      ++it1;
      --it2;
      assert(it1 != active.end());
      assert(it2 != active.end());
      x = (*it1).second;
      y = (*it2).second;
      cur_sum = cur_sum - distance(node, x);
      cur_sum = cur_sum - distance(node, y);
      cur_sum = cur_sum + distance(x, y);
      active.erase(it);
    } else
      cout << cur_sum / 2 << "\n";
  }
  return 0;
}
