#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
set<int> s;
int n;
struct EDGE {
  int num, next, len;
} e[MAXN * 2];
int start[MAXN], en = 0;
inline void Add_edge(int p, int q, int r) {
  en++;
  e[en].num = q;
  e[en].next = start[p];
  start[p] = en;
  e[en].len = r;
  en++;
  e[en].num = p;
  e[en].next = start[q];
  start[q] = en;
  e[en].len = r;
}
int q[MAXN], ql = 0;
int seq[MAXN];
bool u[MAXN];
int fa[23][MAXN], depth[MAXN];
long long fal[23][MAXN];
void dfs(int p) {
  u[p] = true;
  for (int i = start[p]; i != 0; i = e[i].next)
    if (!u[e[i].num]) {
      fa[0][e[i].num] = p;
      fal[0][e[i].num] = e[i].len;
      depth[e[i].num] = depth[p] + 1;
      dfs(e[i].num);
    }
  seq[++ql] = p;
  q[p] = ql;
}
long long getdis(int x, int y) {
  x = seq[x];
  y = seq[y];
  long long res = 0;
  if (depth[x] < depth[y]) swap(x, y);
  int d = depth[x] - depth[y];
  for (int k = 0; k <= 20; k++)
    if (d & (1 << k)) {
      res += fal[k][x];
      x = fa[k][x];
    }
  for (int k = 20; k >= 0; k--)
    if (fa[k][x] != fa[k][y]) {
      res += fal[k][x] + fal[k][y];
      x = fa[k][x];
      y = fa[k][y];
    }
  if (x != y) res += fal[0][x] + fal[0][y];
  return res;
}
long long ans = 0;
void Add() {
  int p;
  scanf("%d", &p);
  p = q[p];
  set<int>::iterator it = s.insert(p).first;
  if (s.size() != 1) {
    set<int>::iterator pre = it, next = it;
    if (pre == s.begin())
      pre = s.end(), pre--;
    else
      pre--;
    next++;
    if (next == s.end()) next = s.begin();
    ans += getdis(*pre, p);
    ans += getdis(*next, p);
    ans -= getdis(*pre, *next);
  }
}
void Del() {
  int p;
  scanf("%d", &p);
  p = q[p];
  set<int>::iterator it = s.find(p);
  if (s.size() != 1) {
    set<int>::iterator pre = it, next = it;
    if (pre == s.begin())
      pre = s.end(), pre--;
    else
      pre--;
    next++;
    if (next == s.end()) next = s.begin();
    ans -= getdis(*pre, p);
    ans -= getdis(*next, p);
    ans += getdis(*pre, *next);
  }
  s.erase(p);
}
void Ask() { printf("%I64d\n", ans / 2); }
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int p, q, r;
    scanf("%d%d%d", &p, &q, &r);
    Add_edge(p, q, r);
  }
  dfs(1);
  fa[0][1] = 1;
  for (int k = 1; k <= 20; k++) {
    for (int i = 1; i <= n; i++) {
      fa[k][i] = fa[k - 1][fa[k - 1][i]];
      fal[k][i] = fal[k - 1][i] + fal[k - 1][fa[k - 1][i]];
    }
  }
  int T;
  scanf("%d", &T);
  while (T--) {
    char tmp[10];
    scanf("%s", tmp);
    if (tmp[0] == '+')
      Add();
    else if (tmp[0] == '-')
      Del();
    else
      Ask();
  }
  return 0;
}
