#include <bits/stdc++.h>
using namespace std;
inline long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
char ch[4000010];
inline string get() {
  scanf("%s", ch);
  return string(ch);
}
inline void read(long long *a, long long n) {
  for (long long i = 0; i < n; i++) a[i] = in();
}
template <class blank>
inline void out(blank x) {
  cout << x << "\n";
  exit(0);
}
template <class blank, class blank2>
inline void smin(blank &a, blank2 b) {
  a = a <= b ? a : b;
}
template <class blank, class blank2>
inline void smax(blank &a, blank2 b) {
  a = a >= b ? a : b;
}
const long long maxn = 1e5 + 10;
const long long maxm = 4e6 + 10;
const long long maxlg = 20;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 10;
const double eps = 1e-4;
long long v[maxn], c[maxn], u[maxn];
long long root[maxn][maxlg], sumE[maxn][maxlg], h[maxn], sum, start[maxn],
    cur = 0;
vector<long long> g[maxn];
inline void dfs(long long node, long long fa = 0) {
  root[node][0] = fa;
  for (long long i = 1; i < maxlg; i++)
    root[node][i] = root[root[node][i - 1]][i - 1],
    sumE[node][i] = sumE[node][i - 1] + sumE[root[node][i - 1]][i - 1];
  start[node] = cur++;
  for (auto u : g[node]) {
    long long nxt = v[u] ^ ::u[u] ^ node;
    if (nxt == fa) continue;
    sumE[nxt][0] = c[u];
    h[nxt] = h[node] + 1;
    dfs(nxt, node);
  }
}
struct cmp {
  inline bool operator()(const long long &a, const long long &b) const {
    return start[a] < start[b];
  }
};
inline long long lca(long long p, long long q) {
  if (h[p] < h[q]) swap(p, q);
  for (long long i = maxlg - 1; i >= 0; i--)
    if (h[p] - (1 << i) >= h[q]) p = root[p][i];
  if (p == q) return p;
  for (long long i = maxlg - 1; i >= 0; i--)
    if (root[p][i] != root[q][i]) p = root[p][i], q = root[q][i];
  return root[p][0];
}
inline long long get(long long node, long long k) {
  long long ret = 0;
  for (long long i = maxlg - 1; i >= 0; i--)
    if (k & (1 << i)) ret += sumE[node][i], node = root[node][i];
  return ret;
}
inline long long di(long long v, long long u) {
  long long LCA = lca(v, u);
  return get(v, h[v] - h[LCA]) + get(u, h[u] - h[LCA]);
}
set<long long, cmp> st;
inline void insert(long long node) {
  if (st.size()) {
    set<long long>::iterator pre, nxt;
    nxt = pre = st.lower_bound(node);
    if (nxt == st.end()) nxt = st.begin();
    if (pre == st.begin()) {
      pre = st.end();
      pre--;
    } else
      pre--;
    sum += di(node, *pre) + di(node, *nxt) - di(*pre, *nxt);
  }
  st.insert(node);
}
inline void erase(long long node) {
  st.erase(node);
  if (!st.size()) return;
  set<long long>::iterator pre, nxt;
  nxt = pre = st.lower_bound(node);
  if (nxt == st.end()) nxt = st.begin();
  if (pre == st.begin()) {
    pre = st.end();
    pre--;
  } else
    pre--;
  sum -= di(node, *pre) + di(node, *nxt) - di(*pre, *nxt);
}
int32_t main() {
  long long n = in();
  for (long long i = 0; i < n - 1; i++)
    v[i] = in(), u[i] = in(), c[i] = in(), g[v[i]].push_back(i),
    g[u[i]].push_back(i);
  dfs(1);
  long long q = in();
  while (q--) {
    char ch = 0;
    do {
      ch = getchar();
    } while (ch != '+' && ch != '-' && ch != '?');
    if (ch == '+' || ch == '-') {
      long long node = in();
      if (ch == '+')
        insert(node);
      else
        erase(node);
    } else
      cout << sum / 2 << "\n";
  }
}
