#include <bits/stdc++.h>
using namespace std;
const int N = 100012, M = N * 2, H = 18;
int n, m, tim = 0, k, flag[N], pos[N], fa[N][H], d[N];
long long ans = 0, len[N];
set<int> S;
struct Edge {
  int u, v, w;
  Edge *next;
} e[M], *P = e, *point[N];
inline void Add_Edge(int a, int b, int c) {
  P->u = a;
  P->v = b;
  P->w = c;
  P->next = point[a];
  point[a] = P++;
}
void Dfs(int now, int dep, long long l) {
  flag[now] = ++tim;
  pos[tim] = now;
  d[now] = dep;
  len[now] = l;
  for (Edge *j = point[now]; j; j = j->next)
    if (j->v != fa[now][0]) {
      fa[j->v][0] = now;
      Dfs(j->v, dep + 1, l + j->w);
    }
}
int LCA(int a, int b) {
  if (d[a] < d[b]) swap(a, b);
  for (int j = H - 1; j >= 0; --j)
    if (d[fa[a][j]] >= d[b]) a = fa[a][j];
  if (a == b) return a;
  for (int j = H - 1; j >= 0; --j)
    if (fa[a][j] != fa[b][j]) a = fa[a][j], b = fa[b][j];
  return fa[a][0];
}
long long Dist(int u, int v) { return len[u] + len[v] - 2 * len[LCA(u, v)]; }
int main() {
  scanf("%d", &n);
  int a, b, c;
  for (int i = 1; i < n; ++i)
    scanf("%d%d%d", &a, &b, &c), Add_Edge(a, b, c), Add_Edge(b, a, c);
  Dfs(1, 0, 0);
  for (int j = 1; j < H; ++j)
    for (int i = 1; i <= n; ++i) fa[i][j] = fa[fa[i][j - 1]][j - 1];
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    getchar();
    char ch = getchar();
    if (ch == '?') printf("%I64d\n", ans / 2);
    if (ch == '+') {
      scanf("%d", &k);
      if (S.empty()) {
        S.insert(flag[k]);
        continue;
      }
      set<int>::iterator t1 = S.lower_bound(flag[k]), t2;
      if (t1 == S.end() || t1 == S.begin())
        t1 = --S.end(), t2 = S.begin();
      else
        t2 = t1--;
      ans += -Dist(pos[*t1], pos[*t2]) + Dist(pos[*t1], k) + Dist(pos[*t2], k);
      S.insert(flag[k]);
    }
    if (ch == '-') {
      scanf("%d", &k);
      set<int>::iterator t = S.find(flag[k]), t1, t2;
      if (t == S.begin())
        t1 = --S.end();
      else
        t1 = --t, ++t;
      if (++t == S.end())
        t2 = S.begin(), --t;
      else
        t2 = t, --t;
      ans += Dist(pos[*t1], pos[*t2]) - Dist(pos[*t1], k) - Dist(pos[*t2], k);
      S.erase(t);
    }
  }
}
