#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 7;
const int infint = (int)1e9;
vector<pair<long long, long long> > G[MAXN];
long long h[MAXN], par[MAXN][20], cost[MAXN][20], st[MAXN], tme = 0, q;
set<pair<int, int> > black;
void dfs_pre(int u, int p) {
  st[u] = tme;
  for (auto v : G[u])
    if (v.first != p) {
      h[v.first] = h[u] + 1;
      par[v.first][0] = u;
      cost[v.first][0] = v.second;
      tme++;
      dfs_pre(v.first, u);
    }
}
long long lca(int u, int v) {
  if (h[u] > h[v]) swap(u, v);
  for (int i = 19; i >= 0; i--)
    if (h[v] - (1 << i) >= h[u]) v = par[v][i];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--)
    if (par[u][i] != par[v][i] && par[u][i] != -1 && par[v][i] != -1)
      u = par[u][i], v = par[v][i];
  return par[u][0];
}
long long func(long long x, long long y) {
  long long ans = 0;
  long long c = lca(x, y);
  for (int i = 19; i >= 0; i--)
    if (h[x] - (1 << i) >= h[c]) ans += cost[x][i], x = par[x][i];
  for (int i = 19; i >= 0; i--)
    if (h[y] - (1 << i) >= h[c]) ans += cost[y][i], y = par[y][i];
  return ans;
}
int getlow(int u) {
  pair<int, int> p = {st[u], u};
  if (black.size() == 0 || (*black.begin()).first > st[u]) return -1;
  auto it = black.lower_bound(p);
  it--;
  return (*it).second;
}
int getup(int u) {
  pair<int, int> p = {st[u], u};
  if (black.upper_bound(p) == black.end()) return -1;
  return (*black.upper_bound(p)).second;
}
long long add(int u) {
  long long ans = 0;
  int low = getlow(u), up = getup(u);
  if (low != -1 && up != -1) {
    ans -= func(low, up);
    ans += func(low, u);
    ans += func(u, up);
    black.insert({st[u], u});
  } else if (low == -1 && up == -1)
    black.insert({st[u], u});
  else {
    int fir = (*black.begin()).second, last = (*black.rbegin()).second;
    ans -= func(fir, last);
    ans += func(last, u);
    ans += func(u, fir);
    black.insert({st[u], u});
  }
  return ans;
}
long long del(int u) {
  pair<int, int> p = {st[u], u};
  black.erase(p);
  long long ans = -add(u);
  black.erase(p);
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }
  memset(par, -1, sizeof par);
  dfs_pre(1, -1);
  for (int i = 1; i < 20; i++)
    for (int j = 1; j <= n; j++)
      if (par[j][i - 1] != -1) par[j][i] = par[par[j][i - 1]][i - 1];
  for (int i = 1; i < 20; i++)
    for (int j = 1; j <= n; j++)
      if (par[j][i] != -1)
        cost[j][i] = cost[j][i - 1] + cost[par[j][i - 1]][i - 1];
  long long ans = 0;
  cin >> q;
  for (int i = 0; i < q; i++) {
    char type;
    cin >> type;
    if (type == '+') {
      int u;
      cin >> u;
      ans += add(u);
    } else if (type == '-') {
      int u;
      cin >> u;
      ans += del(u);
    } else
      cout << ans / 2 << "\n";
  }
}
