#include <bits/stdc++.h>
using namespace std;
int rd() { return RAND_MAX == 32767 ? ((rand() << 15) ^ rand()) : rand(); }
const int maxn = 100010;
int tot;
long long res;
int g[maxn], dep[maxn], sa[maxn], rk[maxn], d[maxn][18], len[maxn * 2],
    nxt[maxn * 2], vec[maxn * 2];
long long path[maxn];
set<int> S;
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int delta = dep[x] - dep[y];
  for (int i = 0; i < 18; i++)
    if (delta >> i & 1) x = d[x][i];
  if (x == y) return x;
  for (int i = 17; i >= 0; i--)
    if (d[x][i] != d[y][i]) {
      x = d[x][i];
      y = d[y][i];
    }
  return d[x][0];
}
void dfs(int t) {
  rk[t] = tot;
  sa[tot++] = t;
  for (int i = 0; d[t][i] != -1; i++) d[t][i + 1] = d[d[t][i]][i];
  for (int i = g[t]; i != -1; i = nxt[i])
    if (vec[i] != d[t][0]) {
      d[vec[i]][0] = t;
      dep[vec[i]] = dep[t] + 1;
      path[vec[i]] = path[t] + len[i];
      dfs(vec[i]);
    }
}
void modify(int x, char opt) {
  if (opt == '-') S.erase(rk[x]);
  if (S.size()) {
    set<int>::iterator it = S.lower_bound(rk[x]);
    int R = sa[it == S.end() ? *S.begin() : *it];
    int L = sa[it == S.begin() ? *S.rbegin() : *(--it)];
    res += (path[x] - path[lca(x, L)] - path[lca(x, R)] + path[lca(L, R)]) *
           (opt == '+' ? 1 : -1);
  }
  if (opt == '+') S.insert(rk[x]);
}
int main() {
  int n, m;
  cin >> n;
  tot = 0;
  memset(g, -1, sizeof(g));
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    len[tot] = w, vec[tot] = v, nxt[tot] = g[u], g[u] = tot++;
    len[tot] = w, vec[tot] = u, nxt[tot] = g[v], g[v] = tot++;
  }
  tot = dep[0] = path[0] = 0;
  memset(d, -1, sizeof(d));
  dfs(0);
  cin >> m;
  res = 0;
  for (int i = 0; i < m; i++) {
    char opt;
    while ((cin >> opt) && opt != '+' && opt != '-' && opt != '?')
      ;
    if (opt == '?')
      cout << res << endl;
    else {
      int x;
      cin >> x;
      modify(x - 1, opt);
    }
  }
  return 0;
}
