#include <bits/stdc++.h>
using namespace std;
const int N = 1E5 + 10, lst = 18;
int n, T;
set<pair<int, int> > S;
int hd[N], nxt[N << 1], to[N << 1], vl[N << 1], cnt;
int fo[N][lst + 1], dep[N], dfn[N], sum = 0;
long long dis[N], ans = 0;
inline void init(int x, int y, int v) {
  cnt++;
  nxt[cnt] = hd[x];
  hd[x] = cnt;
  to[cnt] = y;
  vl[cnt] = v;
}
inline void dfs(int x, int pre) {
  fo[x][0] = pre;
  dep[x] = dep[pre] + 1;
  dfn[x] = ++sum;
  for (int i = hd[x]; i; i = nxt[i]) {
    int u = to[i];
    if (u != pre) {
      dis[u] = dis[x] + vl[i];
      dfs(u, x);
    }
  }
}
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = lst; i >= 0; i--) {
    if (dep[fo[x][i]] >= dep[y]) x = fo[x][i];
    if (dep[x] == dep[y]) break;
  }
  if (x == y) return x;
  for (int i = lst; i >= 0; i--) {
    if (fo[x][i] != fo[y][i]) {
      x = fo[x][i];
      y = fo[y][i];
    }
  }
  return fo[x][0];
}
inline long long Dis(int x, int y) {
  return dis[x] + dis[y] - 2 * dis[lca(x, y)];
}
inline char rd(void) {
  char c;
  while (c = getchar(), c != '+' && c != '-' && c != '?')
    ;
  return c;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y, v;
    scanf("%d%d%d", &x, &y, &v);
    init(x, y, v);
    init(y, x, v);
  }
  dfs(1, 1);
  for (int j = 1; j <= lst; j++) {
    for (int i = 1; i <= n; i++) {
      fo[i][j] = fo[fo[i][j - 1]][j - 1];
    }
  }
  scanf("%d", &T);
  while (T--) {
    char c = rd();
    int x;
    if (c == '?')
      printf("%lld\n", ans / 2);
    else {
      scanf("%d", &x);
      pair<int, int> res = make_pair(dfn[x], x);
      if (c == '-') S.erase(res);
      if (S.size()) {
        int l, r;
        set<pair<int, int> >::iterator it = S.upper_bound(res);
        if (it == S.end()) {
          it--;
          l = (*it).second, r = (*S.begin()).second;
        } else if (it == S.begin()) {
          l = (*S.rbegin()).second, r = (*it).second;
        } else {
          l = (*it).second;
          it--;
          r = (*it).second;
        }
        ans += Dis(x, l) * (c == '+' ? 1 : -1) +
               Dis(x, r) * (c == '+' ? 1 : -1) -
               Dis(r, l) * (c == '+' ? 1 : -1);
      }
      if (c == '+') S.insert(res);
    }
  }
  return 0;
}
