#include <bits/stdc++.h>
using namespace std;
const int LOGN = 23;
const int NMAX = 1e5 + 7;
long long n, q, id[NMAX], tin[NMAX], we[NMAX], h[NMAX], par[LOGN][NMAX];
long long res = 0;
vector<pair<long long int, long long int> > g[NMAX];
int Time = 0;
void Dfs(int node, int p) {
  h[node] = h[p] + 1;
  par[0][node] = p;
  tin[node] = ++Time;
  id[Time] = node;
  for (pair<long long int, long long int> i : g[node]) {
    if (i.first != p) {
      we[i.first] = we[node] + i.second;
      Dfs(i.first, node);
    }
  }
}
int LCA(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  int d = h[u] - h[v];
  for (int i = 0; i < LOGN; i++)
    if (d & (1 << i)) u = par[i][u];
  if (u == v) return u;
  for (int i = LOGN - 1; i >= 0; i--) {
    if (par[i][u] != par[i][v]) {
      u = par[i][u];
      v = par[i][v];
    }
  }
  return par[0][u];
}
long long dist(int u, int v) { return we[u] + we[v] - 2 * we[LCA(u, v)]; }
set<long long> second;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  Dfs(1, 0);
  for (int i = 1; i < LOGN; i++)
    for (int j = 1; j <= n; j++) par[i][j] = par[i - 1][par[i - 1][j]];
  cin >> q;
  while (q--) {
    char c;
    cin >> c;
    if (c == '+') {
      int x;
      cin >> x;
      if (second.size() == 0) {
        second.insert(tin[x]);
        res = 0;
        continue;
      }
      set<long long>::iterator it = second.upper_bound(tin[x]);
      int posle = it == second.end() ? *second.begin() : *it;
      ;
      int pre = it == second.begin() ? *second.rbegin() : *--it;
      long long dodaj =
          (dist(x, id[posle]) + dist(x, id[pre]) - dist(id[pre], id[posle])) /
          2;
      res += dodaj;
      second.insert(tin[x]);
    }
    if (c == '-') {
      int x;
      cin >> x;
      if (second.size() == 1) {
        second.erase(tin[x]);
        res = 0;
        continue;
      }
      second.erase(tin[x]);
      set<long long>::iterator it = second.upper_bound(tin[x]);
      int posle = it == second.end() ? *second.begin() : *it;
      int pre = it == second.begin() ? *second.rbegin() : *--it;
      long long oduzmi =
          (dist(x, id[posle]) + dist(x, id[pre]) - dist(id[pre], id[posle])) /
          2;
      res -= oduzmi;
    }
    if (c == '?') cout << res << endl;
  }
  return 0;
}
