#include <bits/stdc++.h>
using namespace std;
inline int readint() {
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x;
}
inline long long readlong() {
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  long long x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x;
}
set<pair<int, int> > S;
vector<pair<int, int> > G[100005];
int dfn[100005];
long long dis[100005];
queue<int> Q;
int go[100005][17];
int dep[100005];
int tdfn;
int n;
void init() { memset(go, -1, sizeof(go)); }
void addEdge(int u, int v, int w) {
  G[u].push_back(make_pair(v, w));
  G[v].push_back(make_pair(u, w));
}
void dfs(int u, int fa, long long d) {
  dis[u] = d;
  dfn[u] = tdfn++;
  for (__typeof((G[u]).begin()) i = (G[u]).begin(); i != (G[u]).end(); ++i) {
    pair<int, int> tmp = *i;
    int v = tmp.first, w = tmp.second;
    if (v == fa) continue;
    dfs(v, u, w + d);
  }
}
void bfs() {
  Q.push(1);
  dep[1] = 1;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = 0; go[u][i] != -1 && go[go[u][i]][i] != -1; i++) {
      go[u][i + 1] = go[go[u][i]][i];
    }
    for (__typeof((G[u]).begin()) i = (G[u]).begin(); i != (G[u]).end(); ++i) {
      pair<int, int> tmp = *i;
      int v = tmp.first;
      if (dep[v]) continue;
      dep[v] = dep[u] + 1;
      go[v][0] = u;
      Q.push(v);
    }
  }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  for (int i = 0; i < (int)(17); i++) {
    if ((d & (1 << i)) > 0) {
      u = go[u][i];
    }
  }
  if (u == v) return u;
  for (int i = (int)(16); i >= (int)(0); i--) {
    if (go[u][i] != go[v][i]) {
      u = go[u][i];
      v = go[v][i];
    }
  }
  return go[u][0];
}
int main() {
  init();
  scanf("%d", &n);
  int a, b, c;
  for (int i = 0; i < (int)(n - 1); i++) {
    scanf("%d%d%d", &a, &b, &c);
    addEdge(a, b, c);
  }
  dfs(1, -1, 0);
  bfs();
  char ss[3];
  int m;
  scanf("%d", &m);
  long long sum = 0;
  set<pair<int, int> >::iterator it;
  for (int i = 0; i < (int)(m); i++) {
    scanf("%s", ss);
    if (ss[0] == '?') {
      printf("%I64d\n", sum >> 1);
    } else if (ss[0] == '+') {
      scanf("%d", &a);
      if (S.size() == 0) {
        S.insert(make_pair(dfn[a], a));
      } else {
        it = S.lower_bound(make_pair(dfn[a], a));
        if (it == S.end()) it = S.begin();
        int nxt = (*it).second;
        if (it == S.begin()) it = S.end();
        it--;
        int pre = (*it).second;
        S.insert(make_pair(dfn[a], a));
        sum -= dis[pre] + dis[nxt] - 2 * dis[lca(pre, nxt)];
        sum += dis[pre] + dis[a] - 2 * dis[lca(pre, a)];
        sum += dis[nxt] + dis[a] - 2 * dis[lca(nxt, a)];
      }
    } else {
      scanf("%d", &a);
      it = S.upper_bound(make_pair(dfn[a], a));
      if (it == S.end()) it = S.begin();
      int nxt = (*it).second;
      it = S.find(make_pair(dfn[a], a));
      if (it == S.begin()) it = S.end();
      it--;
      int pre = (*it).second;
      S.erase(S.find(make_pair(dfn[a], a)));
      sum += dis[pre] + dis[nxt] - 2 * dis[lca(pre, nxt)];
      sum -= dis[pre] + dis[a] - 2 * dis[lca(pre, a)];
      sum -= dis[nxt] + dis[a] - 2 * dis[lca(nxt, a)];
    }
  }
  return 0;
}
