#include <bits/stdc++.h>
using namespace std;
using namespace rel_ops;
const double PI = acos((double)-1);
long long gcd(long long x, long long y) {
  long long t;
  for (; y != 0;) {
    t = x % y;
    x = y;
    y = t;
  }
  return x;
}
double sqr(double x) { return x * x; }
template <class T>
void mn(T& x, T y) {
  x = min(x, y);
}
template <class T>
void mx(T& x, T y) {
  x = max(x, y);
}
long long n, i, a, b, c, now, x, Q, ans, Max_l = 20, Number;
long long e[200005], succ[200005], last[200005], Val[200005], sum;
long long Up[100005][21], Dis[100005], Depth[100005];
long long tot, DFSlist[100005], DFSID[100005], SEGID[100005];
long long Left[400005], Right[400005], Min[400005], Max[400005], Ans;
char kind;
void Dfs(long long now, long long f);
long long Get_Dis(long long a, long long b);
void Make(long long l, long long r, long long i);
void Ask(long long l, long long r, long long i, long long kind);
void Modi(long long a, long long b);
long long Succ(long long x);
long long Next(long long x);
int main() {
  scanf("%I64d", &n);
  for (i = 1; i < n; i++) {
    scanf("%I64d %I64d %I64d", &a, &b, &c);
    e[++sum] = b, succ[sum] = last[a], last[a] = sum;
    e[++sum] = a, succ[sum] = last[b], last[b] = sum;
    Val[sum] = Val[sum - 1] = c;
  }
  Dfs(1, 0);
  Make(1, n, 1);
  scanf("%I64d\n", &Q);
  while (Q > 0) {
    Q--;
    scanf("%c", &kind);
    if (kind == '?')
      printf("%I64d\n", (ans >> 1)), scanf("\n");
    else if (kind == '+') {
      scanf("%I64d\n", &a);
      Modi(DFSID[a], DFSID[a]);
      Number++;
      if (Number == 1) continue;
      ans -= Get_Dis(DFSlist[Succ(DFSID[a])], DFSlist[Next(DFSID[a])]);
      ans += Get_Dis(DFSlist[Succ(DFSID[a])], a);
      ans += Get_Dis(DFSlist[Next(DFSID[a])], a);
    } else {
      scanf("%I64d\n", &a);
      Modi(DFSID[a], 0);
      Number--;
      if (Number == 0) continue;
      ans += Get_Dis(DFSlist[Succ(DFSID[a])], DFSlist[Next(DFSID[a])]);
      ans -= Get_Dis(DFSlist[Succ(DFSID[a])], a);
      ans -= Get_Dis(DFSlist[Next(DFSID[a])], a);
    }
  }
  return 0;
}
void Dfs(long long now, long long f) {
  long long x, i;
  DFSlist[++tot] = now;
  DFSID[now] = tot;
  if (f == 0) {
    for (i = 0; i <= Max_l; i++) Up[now][i] = now;
  } else {
    Up[now][0] = f;
    for (i = 1; i <= Max_l; i++) Up[now][i] = Up[Up[now][i - 1]][i - 1];
  }
  for (x = last[now]; x != 0; x = succ[x]) {
    if (e[x] == f) continue;
    Dis[e[x]] = Dis[now] + Val[x];
    Depth[e[x]] = Depth[now] + 1;
    Dfs(e[x], now);
  }
  return;
}
long long Get_Dis(long long a, long long b) {
  long long i, temp, D = Dis[a] + Dis[b];
  if (Depth[a] < Depth[b]) temp = a, a = b, b = temp;
  for (i = Max_l; i >= 0; i--)
    if (Depth[Up[a][i]] >= Depth[b]) a = Up[a][i];
  if (a != b) {
    for (i = Max_l; i >= 0; i--)
      if (Up[a][i] != Up[b][i]) a = Up[a][i], b = Up[b][i];
    return D - (Dis[Up[a][0]] << 1);
  }
  return D - (Dis[a] << 1);
}
void Make(long long l, long long r, long long i) {
  long long mid = (l + r) >> 1;
  Left[i] = l, Right[i] = r, Min[i] = n + 1;
  if (l == r) {
    SEGID[l] = i;
    return;
  }
  Make(l, mid, (i << 1));
  Make(mid + 1, r, ((i << 1) | 1));
  return;
}
void Ask(long long l, long long r, long long i, long long kind) {
  if (l > Right[i] || r < Left[i]) return;
  if (l <= Left[i] && r >= Right[i]) {
    if (kind == 0 && Min[i] < Ans) Ans = Min[i];
    if (kind == 1 && Max[i] > Ans) Ans = Max[i];
    return;
  }
  Ask(l, r, (i << 1), kind);
  Ask(l, r, ((i << 1) | 1), kind);
  return;
}
void Modi(long long a, long long b) {
  long long now = SEGID[a], lc, rc;
  Min[now] = Max[now] = b;
  if (Min[now] == 0) Min[now] = n + 1;
  now >>= 1;
  while (now >= 1) {
    lc = (now << 1), rc = (lc | 1);
    if (Min[lc] < Min[rc])
      Min[now] = Min[lc];
    else
      Min[now] = Min[rc];
    if (Max[lc] > Max[rc])
      Max[now] = Max[lc];
    else
      Max[now] = Max[rc];
    now >>= 1;
  }
  return;
}
long long Succ(long long x) {
  if (x != 1) {
    Ans = 0;
    Ask(1, x - 1, 1, 1);
    if (Ans != 0) return Ans;
  }
  Ans = 0;
  Ask(x + 1, n, 1, 1);
  return Ans;
}
long long Next(long long x) {
  if (x != n) {
    Ans = n + 1;
    Ask(x + 1, n, 1, 0);
    if (Ans != n + 1) return Ans;
  }
  Ans = n + 1;
  Ask(1, x - 1, 1, 0);
  return Ans;
}
