#include <bits/stdc++.h>
using namespace std;
set<int> Q;
bool use[100010];
long long dis[100010], ans;
int dep[100010], F[100010][20];
int seq[100010], pos[100010], top, n;
int Log[100010];
struct Node {
  int v, dis;
  Node() {}
  Node(int v, int dis) : v(v), dis(dis) {}
};
vector<Node> to[100010];
void read() {
  scanf("%d", &n);
  for (int i = 2, a, b, c; i <= n; ++i) {
    scanf("%d %d %d", &a, &b, &c);
    to[a].push_back(Node(b, c));
    to[b].push_back(Node(a, c));
  }
  for (int i = 2; i <= n; ++i) Log[i] = Log[i - 1] + (i == (i & (-i)));
  dep[1] = 1;
}
void DFS(int p) {
  for (int i = 1; i <= Log[dep[p]]; i++) F[p][i] = F[F[p][i - 1]][i - 1];
  seq[++top] = p, pos[p] = top, use[p] = true;
  for (int i = 0; i < to[p].size(); ++i)
    if (use[to[p][i].v] == 0) {
      F[to[p][i].v][0] = p;
      dis[to[p][i].v] = dis[p] + to[p][i].dis;
      dep[to[p][i].v] = dep[p] + 1;
      DFS(to[p][i].v);
    }
}
int LCA(int a, int b) {
  if (dep[a] < dep[b]) swap(a, b);
  for (int i = Log[dep[a]]; i >= 0; --i)
    if (dep[F[a][i]] >= dep[b]) {
      a = F[a][i];
      if (dep[a] == dep[b]) break;
    }
  if (a == b) return a;
  for (int i = Log[dep[a]]; i >= 0; --i)
    if (F[a][i] != F[b][i]) a = F[a][i], b = F[b][i];
  return F[a][0];
}
long long Query(int a, int b) {
  int c = LCA(a, b);
  return dis[a] + dis[b] - 2 * dis[c];
}
long long Insert(int a) {
  long long ans = 0, b, c;
  set<int>::iterator L, R, S, T;
  S = Q.begin(), T = Q.end();
  T--;
  S++, T--;
  L = R = Q.insert(pos[a]).first;
  L--, R++;
  if (*L == 0 && *R == n + 1) return 0;
  if (*L == 0) {
    ans = ans - Query(seq[*S], seq[*T]) + Query(a, seq[*R]) + Query(a, seq[*T]);
    return ans;
  } else if (*R == n + 1) {
    ans = ans - Query(seq[*S], seq[*T]) + Query(a, seq[*L]) + Query(a, seq[*S]);
    return ans;
  } else {
    ans = ans + Query(seq[*L], a);
    ans = ans + Query(seq[*R], a);
    ans = ans - Query(seq[*L], seq[*R]);
    return ans;
  }
}
long long Delete(int a) {
  long long ans = 0, b, c;
  set<int>::iterator L, R, S, T, it;
  S = Q.begin(), T = Q.end();
  T--;
  S++, T--;
  it = L = R = Q.insert(pos[a]).first;
  L--, R++;
  Q.erase(it);
  if (*L == 0 && *R == n + 1) return 0;
  if (*L == 0) {
    ans = ans - Query(seq[*R], seq[*T]) + Query(a, seq[*R]) + Query(a, seq[*T]);
    return ans;
  } else if (*R == n + 1) {
    ans = ans - Query(seq[*S], seq[*L]) + Query(a, seq[*L]) + Query(a, seq[*S]);
    return ans;
  } else {
    ans = ans + Query(seq[*L], a);
    ans = ans + Query(seq[*R], a);
    ans = ans - Query(seq[*L], seq[*R]);
    return ans;
  }
}
void Query() {
  int m;
  static char task[3];
  Q.insert(0), Q.insert(n + 1);
  scanf("%d", &m);
  for (int i = 1, a; i <= m; ++i) {
    scanf("%s", task + 1);
    if (task[1] == '+') {
      scanf("%d", &a);
      ans += Insert(a);
    }
    if (task[1] == '-') {
      scanf("%d", &a);
      ans -= Delete(a);
    }
    if (task[1] == '?') cout << ans / 2 << endl;
  }
}
int main() {
  read();
  DFS(1);
  Query();
  return 0;
}
