#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > S;
long long dist[400005];
long long w[400005];
int f[400005][25];
int dpos[400005];
int last[400005];
int sed[400005];
int sqd[400005];
int seq[400005];
int pos[400005];
int pre[400005];
int e[400005];
int n, m, c, q, sl;
long long ans;
void dfs(int x, long long dep, int h) {
  int i;
  dist[x] = dep;
  seq[++c] = x;
  pos[x] = c;
  sed[++sl] = x;
  sqd[sl] = h;
  dpos[x] = sl;
  for (i = last[x]; i != 0; i = pre[i])
    if (pos[e[i]] == 0) {
      dfs(e[i], dep + w[i], h + 1);
      sed[++sl] = x;
      sqd[sl] = h;
    }
}
void init_rmq() {
  int i, j;
  for (i = 1; i <= sl; ++i) f[i][0] = i;
  for (j = 1; (1 << j) <= sl; ++j)
    for (i = 1; i + j - 1 <= sl; ++i)
      if (sqd[f[i][j - 1]] < sqd[f[i + (1 << (j - 1))][j - 1]])
        f[i][j] = f[i][j - 1];
      else
        f[i][j] = f[i + (1 << (j - 1))][j - 1];
}
int rmq(int l, int r) {
  int k = 0;
  if (l > r) swap(l, r);
  while ((1 << (k + 1)) <= r - l + 1) ++k;
  if (sqd[f[l][k]] < sqd[f[r - (1 << k) + 1][k]])
    return f[l][k];
  else
    return f[r - (1 << k) + 1][k];
}
long long dis(int x, int y) {
  int p;
  p = sed[rmq(dpos[x], dpos[y])];
  return dist[x] + dist[y] - dist[p] * 2;
}
void ins(int x) {
  set<pair<int, int> >::iterator p, ep, le, re;
  p = S.insert(make_pair(pos[x], x)).first;
  ep = S.end(), --ep;
  re = p, ++re;
  if (p != S.begin()) {
    le = p, --le;
    ans += dis(p->second, le->second);
  } else {
    ans += dis(p->second, ep->second);
    if (S.size() > 1) ans -= dis(ep->second, re->second);
  }
  if (re != S.end())
    ans += dis(p->second, re->second);
  else {
    ans += dis(p->second, S.begin()->second);
    if (S.size() > 1) ans -= dis(S.begin()->second, le->second);
  }
  if (p != S.begin() && re != S.end()) ans -= dis(le->second, re->second);
}
void del(int x) {
  set<pair<int, int> >::iterator p, ep, le, re;
  p = S.find(make_pair(pos[x], x));
  ep = S.end(), --ep;
  re = p, ++re;
  if (p != S.begin()) {
    le = p, --le;
    ans -= dis(p->second, le->second);
  } else {
    ans -= dis(p->second, ep->second);
    if (S.size() > 1) ans += dis(ep->second, re->second);
  }
  if (re != S.end())
    ans -= dis(p->second, re->second);
  else {
    ans -= dis(p->second, S.begin()->second);
    if (S.size() > 1) {
      le = p, --le;
      ans += dis(S.begin()->second, le->second);
    }
  }
  if (p != S.begin() && re != S.end()) ans += dis(le->second, re->second);
  S.erase(p);
}
int main() {
  int i, x, y;
  long long w1;
  char opr;
  scanf("%d", &n);
  for (i = 1; i < n; ++i) {
    scanf("%d%d%I64d", &x, &y, &w1);
    (e[++m] = y, pre[m] = last[x], last[x] = m, w[m] = w1),
        (e[++m] = x, pre[m] = last[y], last[y] = m, w[m] = w1);
  }
  dfs(1, 0, 1);
  init_rmq();
  scanf("%d\n", &q);
  for (i = 1; i <= q; ++i) {
    scanf("%c", &opr);
    switch (opr) {
      case '+': {
        scanf("%d", &x);
        ins(x);
        break;
      }
      case '-': {
        scanf("%d", &x);
        del(x);
        break;
      }
      case '?': {
        printf("%I64d\n", ans / 2);
        break;
      }
    }
    scanf("\n");
  }
  return 0;
}
