#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
struct node {
  int to;
  long long dis;
  node() {}
  node(int a, long long b) : to(a), dis(b) {}
};
vector<node> g[maxn];
int dep[maxn], dfs[maxn], sum, tot[maxn], f[maxn], d[maxn][30], st;
long long dis[maxn], ans;
int lca(int x, int y) {
  st = 18;
  if (dep[x] < dep[y]) swap(x, y);
  while (dep[x] != dep[y]) {
    if (dep[d[x][st]] >= dep[y]) x = d[x][st];
    st--;
  }
  st = 18;
  if (x == y) return x;
  while (1) {
    if (f[x] == f[y]) return f[x];
    if (d[x][st] != d[y][st]) x = d[x][st], y = d[y][st];
    st--;
  }
}
int fa[maxn], son[maxn][2], num[maxn], root, head, tail;
void rotate(int p) {
  int x = fa[p], cnt = p == son[x][1], y = son[p][cnt ^ 1], z = fa[x];
  if (y != 0) fa[y] = x;
  if (x == son[z][0]) son[z][0] = p;
  if (x == son[z][1]) son[z][1] = p;
  fa[x] = p, son[x][cnt] = y, fa[p] = z, son[p][cnt ^ 1] = x;
}
void splay(int p) {
  while (fa[p] != 0) {
    int x = fa[p], y = fa[x];
    if (y == 0)
      rotate(p);
    else if ((p == son[x][0]) ^ (x == son[y][0]))
      rotate(p), rotate(p);
    else
      rotate(x), rotate(p);
  }
  root = p;
}
int pre(int x) {
  if (son[x][0] == 0) return 0;
  for (int i = son[x][0];; i = son[i][1])
    if (son[i][1] == 0) return i;
}
int suf(int x) {
  if (son[x][1] == 0) return 0;
  for (int i = son[x][1];; i = son[i][0])
    if (son[i][0] == 0) return i;
}
long long dist(int x, int y) { return dis[x] + dis[y] - dis[lca(x, y)] * 2; }
void Insert(int x, int p) {
  if (root == 0) {
    root = x, num[x] = p, head = tail = x;
    return;
  }
  for (int i = root;; i = son[i][p > num[i]])
    if (son[i][p > num[i]] == 0) {
      son[i][p > num[i]] = x;
      fa[x] = i, num[x] = p;
      splay(x);
      break;
    }
  int a = pre(x), b = suf(x);
  if (a == 0 && b != 0)
    ans += dist(x, b) + dist(x, tail) - dist(b, tail), head = x;
  else if (a != 0 && b == 0)
    ans += dist(x, a) + dist(x, head) - dist(a, head), tail = x;
  else if (a != 0 && b != 0)
    ans += dist(x, a) + dist(x, b) - dist(a, b);
}
void Delete(int x) {
  splay(x);
  int a = pre(x), b = suf(x);
  if (a == 0 && b != 0)
    ans -= dist(x, b) + dist(x, tail) - dist(b, tail), head = b;
  else if (a != 0 && b == 0)
    ans -= dist(x, a) + dist(x, head) - dist(a, head), tail = a;
  else if (a != 0 && b != 0)
    ans -= dist(x, a) + dist(x, b) - dist(a, b);
  if (son[x][0] == 0 && son[x][1] == 0)
    root = head = tail = 0;
  else if (son[x][0] == 0 && son[x][1] != 0)
    root = son[x][1], fa[root] = 0;
  else if (son[x][0] != 0 && son[x][1] == 0)
    root = son[x][0], fa[root] = 0;
  else {
    fa[son[x][0]] = 0, son[a][1] = son[x][1], fa[son[x][1]] = a;
    splay(a);
  }
  son[x][0] = son[x][1] = 0;
}
void fd(int x, int cur, long long cnt, int father) {
  dep[x] = cur, dis[x] = cnt, dfs[x] = ++sum, f[x] = father, d[x][0] = f[x];
  for (int i = 1; i <= 18; i++) d[x][i] = d[d[x][i - 1]][i - 1];
  for (int i = 0; i < g[x].size(); i++)
    if (g[x][i].to != f[x]) fd(g[x][i].to, cur + 1, cnt + g[x][i].dis, x);
}
int main() {
  int n, t, x, y, a, b;
  long long c;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d %d %I64d", &a, &b, &c);
    g[a].push_back(node(b, c));
    g[b].push_back(node(a, c));
  }
  fd(1, 1, 0, 0);
  scanf("%d\n", &t);
  while (t--) {
    char f;
    scanf("%c", &f);
    if (f == '+') {
      scanf("%d\n", &x);
      Insert(x, sum - dfs[x] + 1);
    } else if (f == '-') {
      scanf("%d\n", &x);
      Delete(x);
    } else {
      printf("%I64d\n", ans / 2);
      getchar();
    }
  }
  return 0;
}
