#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10, MAXL = 20;
struct Graph {
  int id, next, dis;
} g[MAXN * 2];
long long dis[MAXN];
int n, st[MAXN], DFN[MAXN], pos[MAXN], dep[MAXN], f[MAXN][MAXL];
set<int> s;
void Add(int tot, int x, int y, int dis) {
  g[tot].id = y, g[tot].next = st[x], g[tot].dis = dis, st[x] = tot;
}
int idx;
void DFS(int x, int fa) {
  DFN[x] = ++idx;
  pos[idx] = x;
  for (int i = st[x]; i != -1; i = g[i].next)
    if (g[i].id != fa) {
      dis[g[i].id] = dis[x] + g[i].dis;
      dep[g[i].id] = dep[x] + 1;
      f[g[i].id][0] = x;
      for (int j = 1; j < MAXL; ++j)
        f[g[i].id][j] = f[f[g[i].id][j - 1]][j - 1];
      DFS(g[i].id, x);
    }
}
void init() {
  scanf("%d", &n);
  memset(st, -1, sizeof(st));
  for (int i = 1; i < n; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    Add(i * 2, x, y, z);
    Add(i * 2 + 1, y, x, z);
  }
  dep[0] = -1;
  DFS(1, 0);
}
char str[10];
long long CC;
int LCA(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  for (int i = MAXL - 1; i >= 0; --i)
    if (dep[f[y][i]] >= dep[x]) y = f[y][i];
  if (x == y) return x;
  for (int i = MAXL - 1; i >= 0; --i)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
long long work(int x, int y) {
  int z = LCA(x, y);
  return dis[x] + dis[y] - dis[z] * 2;
}
long long calc(int dfn) {
  if (s.size() == 1) return 0;
  set<int>::iterator it = s.lower_bound(dfn), l, r;
  if (it == s.begin())
    l = s.end(), --l;
  else
    l = it, --l;
  r = it;
  ++r;
  if (r == s.end()) r = s.begin();
  return (work(pos[*it], pos[*l]) + work(pos[*it], pos[*r]) -
          work(pos[*l], pos[*r])) /
         2;
}
void solve() {
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int x;
    scanf("%s", str);
    if (str[0] == '?') {
      cout << CC << endl;
      continue;
    }
    scanf("%d", &x);
    if (str[0] == '+') s.insert(DFN[x]);
    CC += calc(DFN[x]) * ((str[0] == '+') ? (1) : (-1));
    if (str[0] == '-') s.erase(DFN[x]);
  }
}
int main() {
  init();
  solve();
  fclose(stdin);
  fclose(stdout);
  return 0;
}
