#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (flag) x = -x;
}
using namespace std;
int n;
struct edge {
  int nxt;
  int to;
  int val;
} e[101000 << 1];
int head[101000], ecnt;
inline void addedge(int from, int to, int val) {
  e[++ecnt] = (edge){head[from], to, val};
  head[from] = ecnt;
}
int dep[101000], siz[101000], fa[101000], son[101000];
long long dis[101000];
void dfs_son(int cur, int faa) {
  fa[cur] = faa;
  siz[cur] = 1;
  dep[cur] = dep[faa] + 1;
  int mx = 0;
  for (register int i = head[cur]; i; i = e[i].nxt) {
    int to = e[i].to;
    if (to == faa) continue;
    dis[to] = dis[cur] + e[i].val;
    dfs_son(to, cur);
    siz[cur] += siz[to];
    if (siz[to] > mx) mx = siz[to], son[cur] = to;
  }
}
int top[101000], dfn[101000], dcnt, dedfn[101000];
void dfs_chain(int cur, int topp) {
  top[cur] = topp;
  dfn[cur] = ++dcnt;
  dedfn[dcnt] = cur;
  if (!son[cur]) return;
  dfs_chain(son[cur], topp);
  for (register int i = head[cur]; i; i = e[i].nxt) {
    int to = e[i].to;
    if (to == fa[cur] || to == son[cur]) continue;
    dfs_chain(to, to);
  }
}
inline int get_lca(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  return dep[x] < dep[y] ? x : y;
}
inline long long get_dis(int x, int y) {
  int lca = get_lca(x, y);
  long long res = dis[x] + dis[y] - (dis[lca] << 1);
  return res;
}
set<int> st;
long long ans;
int main() {
  read(n);
  for (register int i = 1; i < n; ++i) {
    int u, v, w;
    read(u), read(v), read(w);
    addedge(u, v, w), addedge(v, u, w);
  }
  dfs_son(1, 0);
  dfs_chain(1, 1);
  int q;
  read(q);
  int ct = 0;
  st.insert(-1);
  st.insert(n + 1);
  while (q--) {
    char ch[3];
    scanf("%s", ch);
    if (ch[0] == '+') {
      int cur;
      read(cur);
      if (ct) {
        int d = dfn[cur];
        set<int>::iterator nxt = st.lower_bound(d), pre = nxt;
        --pre;
        if ((*nxt) == n + 1) nxt = (++st.begin());
        if ((*pre) == -1) pre = --(--(st.end()));
        int nxtp = (*nxt), prep = (*pre);
        ans += get_dis(cur, dedfn[nxtp]) + get_dis(cur, dedfn[prep]) -
               get_dis(dedfn[nxtp], dedfn[prep]);
      }
      st.insert(dfn[cur]);
      ++ct;
    } else if (ch[0] == '-') {
      int cur;
      read(cur);
      st.erase(dfn[cur]);
      --ct;
      if (ct) {
        set<int>::iterator nxt = st.lower_bound(dfn[cur]), pre = nxt;
        --pre;
        if ((*nxt) == n + 1) nxt = (++st.begin());
        if ((*pre) == -1) pre = --(--(st.end()));
        int nxtp = (*nxt), prep = (*pre);
        ans -= (get_dis(cur, dedfn[nxtp]) + get_dis(cur, dedfn[prep]) -
                get_dis(dedfn[nxtp], dedfn[prep]));
      }
    } else {
      printf("%lld\n", ans >> 1);
    }
  }
  return 0;
}
