#include <bits/stdc++.h>
using namespace std;
void get(int& x) {
  x = 0;
  char ch;
  while ((ch = getchar()) < 48)
    ;
  for (x = ch ^ 48; (ch = getchar()) >= 48; x = (x << 1) + (x << 3) + (ch ^ 48))
    ;
}
struct Edge {
  int nxt, to, val;
} edgs[100001 * 2];
int head[100001], mp_ord[100001], mp_ind[100001];
int cnt = 0, pre[100001][20], dep[100001];
long long dis[100001];
set<int> s;
void add_edge(int u, int v, int dis) {
  edgs[++cnt].to = v;
  edgs[cnt].val = dis;
  edgs[cnt].nxt = head[u];
  head[u] = cnt;
}
void dfs(int u, int par) {
  mp_ind[u] = ++cnt;
  mp_ord[cnt] = u;
  dep[u] = dep[par] + 1;
  pre[u][0] = par;
  for (int i = 1; (1 << i) <= dep[u]; i++)
    pre[u][i] = pre[pre[u][i - 1]][i - 1];
  for (int i = head[u]; i; i = edgs[i].nxt)
    if (edgs[i].to != par) {
      dis[edgs[i].to] = dis[u] + edgs[i].val;
      dfs(edgs[i].to, u);
    }
}
long long lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int rec1 = u, rec2 = v;
  for (int i = log(dep[u] - dep[v]) / log(2) + 1; i >= 0; i--)
    if (dep[u] - (1 << i) >= dep[v]) u = pre[u][i];
  if (u == v) return dis[rec1] - dis[rec2];
  for (int i = log(dep[u]) / log(2) + 1; i >= 0; i--)
    if (pre[u][i] != pre[v][i]) {
      u = pre[u][i];
      v = pre[v][i];
    }
  return dis[rec1] + dis[rec2] - dis[pre[u][0]] * 2;
}
int main() {
  int n, m;
  get(n);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    get(x);
    get(y);
    get(z);
    add_edge(x, y, z);
    add_edge(y, x, z);
  }
  cnt = 0;
  dfs(1, 0);
  get(m);
  long long preval = 0;
  for (int i = 1; i <= m; i++) {
    char ch = getchar();
    if (ch == '+' || ch == '-') {
      int u;
      get(u);
      set<int>::iterator it1, it2, it3;
      if (ch == '+')
        it1 = it2 = it3 = s.insert(mp_ind[u]).first;
      else
        it1 = it2 = it3 = s.find(mp_ind[u]);
      it3++;
      if (it1 == s.begin()) it2 = s.end();
      if (it3 == s.end()) it3 = s.begin();
      it2--;
      int a1 = mp_ord[*it2], a2 = mp_ord[*it3];
      if (ch == '+')
        preval += lca(a1, u) + lca(u, a2) - lca(a1, a2);
      else {
        preval += lca(a1, a2) - lca(a1, u) - lca(u, a2);
        s.erase(mp_ind[u]);
      }
    }
    if (ch == '?') {
      printf("%lld\n", preval / 2);
      char nul = getchar();
    }
  }
  return 0;
}
