#include <bits/stdc++.h>
using namespace std;
int N, Q;
vector<pair<int, int> > adj[100010];
int tin[100010], invt[100010], dep[100010], par[20][100010];
long long dist[100010];
int timer;
void dfs(int u, int p) {
  tin[u] = timer++;
  par[0][u] = p;
  for (int i = 1; i < 20; i++) {
    int t = par[i - 1][u];
    if (t == -1) break;
    par[i][u] = par[i - 1][t];
  }
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i].first;
    int w = adj[u][i].second;
    if (v == p) continue;
    dist[v] = dist[u] + w;
    dep[v] = dep[u] + 1;
    dfs(v, u);
  }
}
int lca(int a, int b) {
  if (dep[a] < dep[b]) swap(a, b);
  int diff = dep[a] - dep[b];
  for (int i = 0; i < 20; i++) {
    if (diff & (1 << i)) a = par[i][a];
  }
  if (a == b) return a;
  for (int i = 20; i--;) {
    if (par[i][a] != par[i][b]) {
      a = par[i][a];
      b = par[i][b];
    }
  }
  return par[0][a];
}
long long getDist(int a, int b) {
  int x = lca(a, b);
  return dist[a] + dist[b] - 2 * dist[x];
}
set<int> st;
long long sum = 0;
void Add(int v) {
  set<int>::iterator it = st.upper_bound(tin[v]);
  int l = -1;
  int r = -1;
  if (it != st.end()) {
    sum += getDist(v, invt[*it]);
    r = *it;
  } else if (it != st.begin()) {
    sum += getDist(v, invt[*st.begin()]);
    r = *st.begin();
  }
  if (it != st.begin()) {
    sum += getDist(v, invt[*(--it)]);
    l = *it;
  } else if (it != st.end()) {
    it = st.end();
    sum += getDist(v, invt[*(--it)]);
    l = *it;
  }
  if (l != -1 && r != -1) {
    sum -= getDist(invt[l], invt[r]);
  }
  st.insert(tin[v]);
}
void Erase(int v) {
  st.erase(st.find(tin[v]));
  set<int>::iterator it = st.upper_bound(tin[v]);
  int l = -1;
  int r = -1;
  if (it != st.end()) {
    sum -= getDist(v, invt[*it]);
    r = *it;
  } else if (it != st.begin()) {
    sum -= getDist(v, invt[*st.begin()]);
    r = *st.begin();
  }
  if (it != st.begin()) {
    sum -= getDist(v, invt[*(--it)]);
    l = *it;
  } else if (it != st.end()) {
    it = st.end();
    sum -= getDist(v, invt[*(--it)]);
    l = *it;
  }
  if (l != -1 && r != -1) {
    sum += getDist(invt[l], invt[r]);
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N - 1; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    adj[a].push_back(pair<int, int>(b, c));
    adj[b].push_back(pair<int, int>(a, c));
  }
  memset(par, -1, sizeof(par));
  dfs(0, -1);
  for (int i = 0; i < N; i++) invt[tin[i]] = i;
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    char t;
    scanf("\n%c", &t);
    if (t == '+') {
      int v;
      scanf("%d", &v);
      v--;
      Add(v);
    }
    if (t == '-') {
      int v;
      scanf("%d", &v);
      v--;
      Erase(v);
    }
    if (t == '?') {
      printf("%lld\n", sum / 2);
    }
  }
}
