#include <bits/stdc++.h>
using namespace std;
struct E {
  int to, nxt, d;
} b[100005 << 1];
int fst[100005], tot;
void insert(int f, int t, int d) {
  b[++tot] = (E){t, fst[f], d};
  fst[f] = tot;
  b[++tot] = (E){f, fst[t], d};
  fst[t] = tot;
}
int in[100005];
int dfn[100005];
int deep[100005];
long long dis[100005];
int fa[100005][20];
int dfs_c;
void dfs(int x) {
  for (int i = 1; i <= 17; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  dfn[++dfs_c] = x;
  in[x] = dfs_c;
  for (int i = fst[x]; i; i = b[i].nxt) {
    int v = b[i].to;
    if (!in[v]) {
      fa[v][0] = x;
      deep[v] = deep[x] + 1;
      dis[v] = dis[x] + b[i].d;
      dfs(v);
    }
  }
}
int lca(int u, int v) {
  if (deep[u] > deep[v]) swap(u, v);
  int t = deep[v] - deep[u];
  for (int i = 0; i <= 17; i++)
    if ((t >> i) & 1) v = fa[v][i];
  if (u == v) return u;
  for (int i = 17; i >= 0; i--)
    if (fa[u][i] != fa[v][i]) {
      u = fa[u][i];
      v = fa[v][i];
    }
  return fa[u][0];
}
long long query(int u, int v) {
  int l = lca(u, v);
  return dis[u] + dis[v] - 2 * dis[l];
}
char s[5];
set<int> S;
set<int>::iterator it;
int main() {
  int n;
  scanf("%d", &n);
  int x, y, c;
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &c);
    insert(x, y, c);
  }
  deep[1] = 1;
  fa[1][0] = 1;
  dfs(1);
  long long ans = 0;
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%s", s);
    if (s[0] == '+') {
      int y = 0, z = 0;
      scanf("%d", &x);
      S.insert(in[x]);
      it = S.find(in[x]);
      it++;
      if (it != S.end()) {
        y = dfn[*it];
        ans += query(x, y);
      }
      it--;
      if (it != S.begin()) {
        it--;
        z = dfn[*it];
        if (y) ans -= query(y, z);
        ans += query(x, z);
      }
    }
    if (s[0] == '-') {
      int y = 0, z = 0;
      scanf("%d", &x);
      it = S.find(in[x]);
      it++;
      if (it != S.end()) {
        y = dfn[*it];
        ans -= query(x, y);
      }
      it--;
      if (it != S.begin()) {
        it--;
        z = dfn[*it];
        if (y) ans += query(y, z);
        ans -= query(x, z);
      }
      S.erase(in[x]);
    }
    if (s[0] == '?') {
      long long p = ans;
      if (S.size() > 1) {
        set<int>::iterator it2;
        it = S.begin();
        it2 = S.end();
        it2--;
        p += query(dfn[*it], dfn[*it2]);
      }
      printf("%I64d\n", p / 2);
    }
  }
  return 0;
}
