#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000000000000001;
string convertstring(long long n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
int lev[100005], par[100005], st[100005], dp[100005][20], t = 0, end, n;
long long dp2[100005][20];
vector<int> g[100005], cost[100005];
void dfs(int src, int p) {
  st[src] = t++;
  par[src] = p;
  lev[src] = lev[p] + 1;
  dp[src][0] = p;
  for (int i = 1; (1 << i) <= lev[src]; ++i) {
    dp[src][i] = dp[dp[src][i - 1]][i - 1];
    dp2[src][i] = dp2[dp[src][i - 1]][i - 1] + dp2[src][i - 1];
  }
  for (int i = 0; i < g[src].size(); ++i) {
    if (g[src][i] != p) {
      dp2[g[src][i]][0] = cost[src][i];
      dfs(g[src][i], src);
    }
  }
}
long long getwt(int u, int v) {
  if (lev[u] < lev[v]) swap(u, v);
  int diff = lev[u] - lev[v], i;
  long long ret = 0;
  for (i = 18; i >= 0; --i) {
    if (diff & (1 << i)) {
      ret += dp2[u][i];
      u = dp[u][i];
    }
  }
  if (u == v) return ret;
  for (i = 18; i >= 0; --i) {
    if (dp[u][i] != dp[v][i]) {
      ret += dp2[u][i] + dp2[v][i];
      u = dp[u][i];
      v = dp[v][i];
    }
  }
  return ret + dp2[u][0] + dp2[v][0];
}
struct cmp {
  bool operator()(const int x, const int y) const { return st[x] < st[y]; }
};
set<int, cmp> ss;
long long func(int x) {
  set<int, cmp>::iterator it1, it2;
  ss.insert(x);
  it1 = it2 = ss.find(x);
  if (it1 != ss.begin())
    it1--;
  else
    it1 = --ss.end();
  if (it2 != --ss.end())
    it2++;
  else
    it2 = ss.begin();
  return getwt(x, *it1) + getwt(x, *it2) - getwt(*it1, *it2);
}
int main() {
  int i, j;
  scanf("%d", &n);
  ;
  for (i = 0; i < n - 1; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    ;
    g[u].push_back(v);
    cost[u].push_back(w);
    g[v].push_back(u);
    cost[v].push_back(w);
  }
  dfs(1, 0);
  int q, end;
  scanf("%d", &q);
  ;
  char s[5];
  long long ans = 0;
  while (q--) {
    scanf("%s", s);
    if (s[0] == '+') {
      int x;
      scanf("%d", &x);
      ;
      ans += func(x);
    } else if (s[0] == '-') {
      int x;
      scanf("%d", &x);
      ;
      ans -= func(x);
      ss.erase(x);
    } else
      printf("%lld\n", ans / 2);
  }
  return 0;
}
