#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int LG = 18;
int st[N], ft[N], d[N], par[N][LG], tim;
long long h[N];
vector<pair<int, int> > adj[N];
void dfs(int v, int p) {
  st[v] = tim++;
  for (auto tmp : adj[v]) {
    int u = tmp.first;
    if (u != p) {
      d[u] = d[v] + 1;
      h[u] = h[v] + tmp.second;
      par[u][0] = v;
      for (int i = 1; i < LG; i++) par[u][i] = par[par[u][i - 1]][i - 1];
      dfs(u, v);
    }
  }
}
struct cmp {
  bool operator()(int a, int b) { return st[a] < st[b]; }
};
multiset<int, cmp> on;
inline int get_par(int v, int a) {
  for (int i = 0; i < LG; i++)
    if ((a >> i) & 1) v = par[v][i];
  return v;
}
inline int lca(int v, int u) {
  if (d[u] > d[v]) swap(u, v);
  v = get_par(v, d[v] - d[u]);
  if (v == u) return v;
  for (int i = LG - 1; i >= 0; i--)
    if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];
  return par[v][0];
}
inline int nxt(int v) {
  auto it = on.upper_bound(v);
  if (it == on.end()) return *on.begin();
  return *it;
}
inline int prv(int v) {
  auto it = on.lower_bound(v);
  if (it == on.begin()) return *on.rbegin();
  it--;
  return *it;
}
inline long long dis(int u, int v) { return h[u] + h[v] - 2 * h[lca(u, v)]; }
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    adj[v].push_back({u, w});
    adj[u].push_back({v, w});
  }
  dfs(0, -1);
  long long sz = 0;
  int q;
  cin >> q;
  while (q--) {
    char c;
    cin >> c;
    if (c == '?') {
      cout << sz / 2 << "\n";
      continue;
    }
    int p;
    cin >> p;
    p--;
    if (c == '+') {
      if (on.empty())
        on.insert(p);
      else {
        int v = prv(p);
        int u = nxt(p);
        sz += dis(v, p) + dis(p, u) - dis(u, v);
        on.insert(p);
      }
    }
    if (c == '-') {
      int v = prv(p);
      int u = nxt(p);
      sz += dis(u, v) - dis(u, p) - dis(v, p);
      on.erase(p);
    }
  }
  return 0;
}
