#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void Read(T &x) {
  int f = 1;
  char t = getchar();
  while (t < '0' || t > '9') {
    if (t == '-') f = -1;
    t = getchar();
  }
  x = 0;
  while (t >= '0' && t <= '9') {
    x = x * 10 + t - '0';
    t = getchar();
  }
  x *= f;
}
template <class T>
inline void chkmin(T &x, T y) {
  if (x > y) x = y;
}
template <class T>
inline void chkmax(T &x, T y) {
  if (x < y) x = y;
}
const int maxn = 100005;
const int logn = 18;
int n;
int q;
int fst[maxn];
int v[maxn << 1], w[maxn << 1], nxt[maxn << 1];
int e_cn;
long long dis[maxn];
int dep[maxn];
int dfn[maxn];
int dfn_clock;
int fa[logn][maxn];
int depnow;
void addedge(int x, int y, int z) {
  e_cn++;
  v[e_cn] = y, w[e_cn] = z;
  nxt[e_cn] = fst[x], fst[x] = e_cn;
}
void input() {
  int x, y, z;
  Read(n);
  for (int i = 1; i < n; i++) {
    Read(x);
    Read(y);
    Read(z);
    addedge(x, y, z);
    addedge(y, x, z);
  }
  Read(q);
}
void initlca() {
  for (int k = 1; (1 << k) <= n; k++) {
    depnow = k;
    for (int i = 1; i <= n; i++) {
      if (fa[k - 1][i] > 0) {
        fa[k][i] = fa[k - 1][fa[k - 1][i]];
      }
    }
  }
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = depnow; i >= 0; i--) {
    if (fa[i][x] > 0 && dep[fa[i][x]] >= dep[y]) {
      x = fa[i][x];
    }
  }
  if (x == y) return x;
  for (int i = depnow; i >= 0; i--) {
    if (fa[i][x] > 0 && fa[i][y] > 0 && fa[i][x] != fa[i][y]) {
      x = fa[i][x];
      y = fa[i][y];
    }
  }
  return fa[0][x];
}
void dfs(int cn, int pr) {
  dfn[cn] = ++dfn_clock;
  fa[0][cn] = pr;
  for (int i = fst[cn]; i; i = nxt[i]) {
    if (v[i] != pr) {
      dis[v[i]] = dis[cn] + w[i];
      dep[v[i]] = dep[cn] + 1;
      dfs(v[i], cn);
    }
  }
}
void prepare() {
  dfs(1, 0);
  initlca();
}
set<pair<int, int> > s;
inline long long getdist(int x, int y) {
  int t = lca(x, y);
  return dis[x] + dis[y] - 2 * dis[t];
}
inline int getpre(set<pair<int, int> >::iterator res) {
  if (res == s.begin())
    return s.rbegin()->second;
  else
    return (--res)->second;
}
inline int getnex(set<pair<int, int> >::iterator res) {
  res++;
  if (res == s.end())
    return s.begin()->second;
  else
    return res->second;
}
void solve() {
  int x;
  char str[5];
  long long ans = 0;
  pair<int, int> now;
  set<pair<int, int> >::iterator res;
  while (q--) {
    scanf("%s", str);
    if (str[0] == '+') {
      Read(x);
      now = make_pair(dfn[x], x);
      res = s.insert(now).first;
      if (s.size() > 1) {
        ans = ans + getdist(x, getpre(res));
        ans = ans + getdist(x, getnex(res));
      }
      if (s.size() > 2) {
        ans = ans - getdist(getpre(res), getnex(res));
      }
    } else if (str[0] == '-') {
      Read(x);
      now = make_pair(dfn[x], x);
      res = s.lower_bound(now);
      if (s.size() > 1) {
        ans = ans - getdist(x, getpre(res));
        ans = ans - getdist(x, getnex(res));
        if (s.size() > 2) {
          ans = ans + getdist(getpre(res), getnex(res));
        }
      }
      s.erase(res);
    } else {
      if (s.size() <= 1) {
        printf("0\n");
      } else {
        printf("%I64d\n", ans / 2);
      }
    }
  }
}
int main() {
  input();
  prepare();
  solve();
  return 0;
}
