#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, LOG = 20;
long long par[N][LOG], w[N][LOG], Ans = 0, sz = 0;
int fen[N], h[N], st[N], en[N], tim = 0;
vector<pair<int, int> > a[N];
void add(int p, int val) {
  for (p++; p < N; p += (p & (-p))) fen[p] += val;
  return;
}
int get(int p) {
  int ret = 0;
  for (; p > 0; p -= (p & (-p))) ret += fen[p];
  return ret;
}
void build_lca(int v) {
  for (int i = 1; i < LOG; i++) {
    par[v][i] = par[par[v][i - 1]][i - 1];
    w[v][i] = w[par[v][i - 1]][i - 1] + w[v][i - 1];
  }
  return;
}
void dfs(int v, int t = 0, int p = 0) {
  par[v][0] = p;
  w[v][0] = t;
  st[v] = tim++;
  build_lca(v);
  for (auto X : a[v]) {
    int u = X.first, vazn = X.second;
    if (u == p) continue;
    h[u] = h[v] + 1;
    dfs(u, vazn, v);
  }
  en[v] = tim;
}
pair<long long, long long> i_par(int v, int x) {
  if (x < 0) return {0, 0};
  long long Weight = 0, Parent = v;
  for (int i = LOG - 1; i >= 0; i--) {
    if (x & (1 << i)) {
      Weight += w[Parent][i];
      Parent = par[Parent][i];
    }
  }
  return {Parent, Weight};
}
int get_number(int v) {
  if (v == 0) return sz;
  return get(en[v]) - get(st[v]);
}
int f(int v, int need) {
  if (get_number(v) >= need) return v;
  for (int i = LOG - 1; i >= 0; i--) {
    if (get_number(par[v][i]) < need) v = par[v][i];
  }
  return par[v][0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, t;
    cin >> u >> v >> t;
    a[u].push_back({v, t});
    a[v].push_back({u, t});
  }
  dfs(1);
  set<int> ver;
  cin >> q;
  while (q--) {
    char s;
    cin >> s;
    if (s == '?') {
      cout << Ans << '\n';
      continue;
    }
    int v;
    cin >> v;
    if (sz == 1 && s == '-') {
      ver.clear();
      Ans = 0;
      sz = 0;
      add(st[v], -1);
      continue;
    } else if (sz == 0 && s == '+') {
      ver.insert(v);
      Ans = 0;
      sz = 1;
      add(st[v], 1);
      continue;
    } else if (s == '-') {
      int f_parent = f(v, 2);
      Ans -= i_par(v, h[v] - h[f_parent]).second;
      auto it = ver.begin();
      int other = *it;
      if (other == v) {
        it++;
        other = *it;
      }
      int tot_lca = f(other, sz - 1);
      Ans -= i_par(tot_lca, h[tot_lca] - h[f_parent]).second;
      add(st[v], -1);
      sz--;
      ver.erase(v);
      continue;
    } else if (s == '+') {
      int f_parent = f(v, 1);
      Ans += i_par(v, h[v] - h[f_parent]).second;
      auto it = ver.begin();
      int other = *it;
      if (other == v) {
        it++;
        other = *it;
      }
      int tot_lca = f(other, sz);
      Ans += i_par(tot_lca, h[tot_lca] - h[f_parent]).second;
      add(st[v], 1);
      sz++;
      ver.insert(v);
    }
  }
}
