#include <bits/stdc++.h>
using namespace std;
int N, cnt, testcase;
long long ans;
vector<int> C[102013], E[102013];
set<int> T;
int p[102013];
int depth[102013], dfs[102013 * 2];
int f[18][102013];
long long c[18][102013];
inline void travel(int x, int fa) {
  p[x] = cnt;
  dfs[cnt++] = x;
  for (vector<int>::iterator i = E[x].begin(), q = C[x].begin();
       i != E[x].end(); ++i, ++q)
    if (*i != fa) {
      depth[*i] = depth[x] + 1;
      travel(*i, x);
      f[0][*i] = x;
      c[0][*i] = *q;
    }
}
void table() {
  for (int i = 1; i < 18; ++i)
    for (int j = 1; j <= N; ++j) {
      f[i][j] = f[i - 1][f[i - 1][j]];
      c[i][j] = c[i - 1][j] + c[i - 1][f[i - 1][j]];
    }
}
inline long long lca(int x, int y) {
  int a = x, b = y;
  long long ret = 0;
  if (depth[b] > depth[a]) swap(a, b);
  for (int i = 17; i >= 0; --i)
    if ((1 << i) <= depth[a] - depth[b]) {
      ret += c[i][a];
      a = f[i][a];
    }
  if (a == b) return ret;
  for (int i = 17; i >= 0; --i)
    if (f[i][a] != f[i][b]) {
      ret += c[i][a] + c[i][b];
      a = f[i][a];
      b = f[i][b];
    }
  ret += c[0][a] + c[0][b];
  if (ret < 0) int bp = 1;
  return ret;
}
inline void Insert(int x) {
  set<int>::iterator pre = T.upper_bound(x), suc = pre;
  (pre == T.begin()) ? (pre = T.end(), pre--) : (pre--);
  if (suc == T.end()) suc = T.begin();
  ans -= lca(dfs[*suc], dfs[*pre]);
  ans += lca(dfs[x], dfs[*suc]);
  ans += lca(dfs[x], dfs[*pre]);
  T.insert(x);
}
void Delete(int x) {
  set<int>::iterator pre = T.find(x), suc = T.upper_bound(x);
  (pre == T.begin()) ? (pre = T.end(), pre--) : (pre--);
  if (suc == T.end()) suc = T.begin();
  ans += lca(dfs[*suc], dfs[*pre]);
  ans -= lca(dfs[x], dfs[*suc]);
  ans -= lca(dfs[x], dfs[*pre]);
  T.erase(x);
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N - 1; ++i) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    E[x].push_back(y);
    E[y].push_back(x);
    C[x].push_back(c);
    C[y].push_back(c);
  }
  travel(1, 0);
  table();
  scanf("%d ", &testcase);
  while (testcase--) {
    char opt;
    int x;
    scanf("%c ", &opt);
    if (opt == '?') {
      printf("%I64d\n", ans / 2);
    } else {
      scanf("%d ", &x);
      if (opt == '+') {
        if (!T.size()) {
          T.insert(p[x]);
        } else {
          Insert(p[x]);
        }
      } else {
        if (T.size() == 1) {
          T.erase(T.begin(), T.end());
        } else {
          Delete(p[x]);
        }
      }
    }
  }
  return 0;
}
