#include <bits/stdc++.h>
using namespace std;
const int maxn = 100008, maxm = 200008;
int in[maxn], sta[maxn << 1], sta_size, pos[maxn], n;
long long d[maxn], ans;
struct Tedge {
  int start[maxn], tot;
  struct arr {
    int a, next, c;
  } e[maxm];
  void clear() {
    memset(start, 0, sizeof(start));
    tot = 1;
  }
  void add(int x, int y, int z) {
    e[++tot].a = y;
    e[tot].next = start[x];
    start[x] = tot;
    e[tot].c = z;
    e[++tot].a = x;
    e[tot].next = start[y];
    start[y] = tot;
    e[tot].c = z;
  }
} E;
const int Tst_maxn = 200008;
struct Tst {
  int n, log[Tst_maxn];
  long long f[20][Tst_maxn];
  void make(int a[], int len) {
    n = len;
    for (int i = 1; i <= n; i++) f[0][i] = d[a[i]];
    for (int i = 1; i <= 17; i++)
      for (int j = 1; j + (1 << i) - 1 <= n; j++)
        f[i][j] = (f[i - 1][j] < f[i - 1][j + (1 << i - 1)]
                       ? f[i - 1][j]
                       : f[i - 1][j + (1 << i - 1)]);
    for (int i = 1; i <= n; i++)
      for (int j = i >> 1; j; log[i]++, j >>= 1)
        ;
  }
  long long ask(int l, int r) {
    l = pos[l];
    r = pos[r];
    if (r < l) printf("error\n");
    int k = log[r - l + 1];
    return (f[k][l] < f[k][r - (1 << k) + 1] ? f[k][l]
                                             : f[k][r - (1 << k) + 1]);
  }
} St;
struct Tcmp {
  bool operator()(int i, int j) { return pos[i] < pos[j]; }
};
set<int, Tcmp> F;
struct Tprogram {
  void open() {
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
  }
  void close() {
    fclose(stdin);
    fclose(stdout);
  }
  void dfs(int u) {
    in[u] = 1;
    sta[++sta_size] = u;
    pos[u] = sta_size;
    for (int i = E.start[u], v; v = E.e[i].a, i; i = E.e[i].next)
      if (!in[v]) {
        d[v] = d[u] + E.e[i].c;
        dfs(v);
        sta[++sta_size] = u;
      }
  }
  void init() {
    scanf("%d", &n);
    int u, v, w;
    E.clear();
    for (int i = 1; i <= n - 1; i++) {
      scanf("%d%d%d", &u, &v, &w);
      E.add(u, v, w);
    }
    dfs(1);
    St.make(sta, sta_size);
  }
  void Erase(int u) {
    set<int, Tcmp>::iterator p = F.find(u);
    long long x, y;
    if (F.size() > 1) {
      set<int, Tcmp>::iterator l = p, r = p;
      l--;
      r++;
      if (p == F.begin())
        x = St.ask(*p, *r), y = St.ask(*r, *(--F.end()));
      else if (r == F.end())
        x = St.ask(*l, *p), y = St.ask(*F.begin(), *l);
      else {
        x = St.ask(*l, *p), y = St.ask(*p, *r);
        if (x < y) swap(x, y);
      }
      ans -= (y - x > 0 ? y - x : 0) + d[u] - x;
    }
    F.erase(p);
  }
  void Insert(int u) {
    F.insert(u);
    set<int, Tcmp>::iterator p = F.find(u);
    long long x, y;
    if (F.size() > 1) {
      set<int, Tcmp>::iterator l = p, r = p;
      l--;
      r++;
      if (p == F.begin())
        x = St.ask(*p, *r), y = St.ask(*r, *(--F.end()));
      else if (r == F.end())
        x = St.ask(*l, *p), y = St.ask(*F.begin(), *l);
      else {
        x = St.ask(*l, *p), y = St.ask(*p, *r);
        if (x < y) swap(x, y);
      }
      ans += (y - x > 0 ? y - x : 0) + d[u] - x;
    }
  }
  void work() {
    int q, k;
    char s[106];
    scanf("%d", &q);
    for (int i = 1; i <= q; i++) {
      scanf("%s", &s);
      if (s[0] == '?')
        printf("%I64d\n", ans);
      else {
        scanf("%d", &k);
        if (s[0] == '+')
          Insert(k);
        else
          Erase(k);
      }
    }
  }
} Program;
int main() {
  Program.init();
  Program.work();
  return 0;
}
