#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
static int dep[maxn], tmk;
static int Fa[maxn][20], tm[maxn];
static long long F[maxn][20];
set<pair<int, int> > S;
vector<int> A[maxn];
vector<int> B[maxn];
static int n, m;
void dfs(int x, int y, int dp) {
  tm[x] = ++tmk;
  dep[x] = dp;
  for (int i = 0; i < A[x].size(); i++)
    if (A[x][i] != y)
      dfs(A[x][i], x, dp + 1);
    else {
      F[x][0] = B[x][i];
      Fa[x][0] = y;
    }
}
void Build() {
  for (int j = 1; j <= 19; j++)
    for (int i = 1; i <= n; i++) {
      Fa[i][j] = Fa[Fa[i][j - 1]][j - 1];
      F[i][j] = F[i][j - 1] + F[Fa[i][j - 1]][j - 1];
    }
}
long long dis(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  long long d = 0;
  if (dep[x] != dep[y])
    for (int j = 19; j >= 0; j--)
      if (dep[Fa[x][j]] >= dep[y]) {
        d += F[x][j];
        x = Fa[x][j];
      }
  if (x != y) {
    for (int j = 19; j >= 0; j--)
      if (Fa[x][j] != Fa[y][j]) {
        d += F[x][j] + F[y][j];
        x = Fa[x][j];
        y = Fa[y][j];
      }
    d += F[x][0] + F[y][0];
  }
  return d;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    A[x].push_back(y);
    A[y].push_back(x);
    B[x].push_back(w);
    B[y].push_back(w);
  }
  scanf("%d\n", &m);
  dfs(1, 0, 1);
  long long ans = 0;
  Build();
  for (int i = 1; i <= m; i++) {
    char ch = getchar();
    if (ch == '?') {
      if (!S.empty()) {
        set<pair<int, int> >::iterator k = S.end();
        k--;
        int x1 = (*k).second, x2;
        x2 = (*S.begin()).second;
        cout << (ans + dis(x1, x2)) / 2 << endl;
      } else
        cout << (ans) / 2 << endl;
    } else {
      int x;
      scanf("%d", &x);
      if (ch == '+') {
        pair<int, int> Nd = make_pair(tm[x], x);
        S.insert(Nd);
        set<pair<int, int> >::iterator k = S.find(Nd);
        set<pair<int, int> >::iterator k1 = k;
        k1++;
        if (k != S.begin() && k1 != S.end()) {
          int x1 = (*k1).second, x2;
          k1--;
          k1--;
          x2 = (*k1).second;
          ans = ans - dis(x1, x2) + dis(x1, x) + dis(x, x2);
        } else if (k != S.begin() || k1 != S.end()) {
          if (k == S.begin()) {
            int x1 = (*k1).second;
            ans = ans + dis(x, x1);
          } else {
            k1--;
            k1--;
            int x1 = (*k1).second;
            ans = ans + dis(x, x1);
          }
        }
      } else {
        pair<int, int> Nd = make_pair(tm[x], x);
        set<pair<int, int> >::iterator k = S.find(Nd);
        set<pair<int, int> >::iterator k1 = k;
        k1++;
        if (k != S.begin() && k1 != S.end()) {
          int x1 = (*k1).second, x2;
          k1--;
          k1--;
          x2 = (*k1).second;
          ans -= -dis(x1, x2) + dis(x1, x) + dis(x, x2);
        } else if (k != S.begin() || k1 != S.end()) {
          if (k == S.begin()) {
            int x1 = (*k1).second;
            ans -= dis(x, x1);
          } else {
            k1--;
            k1--;
            int x1 = (*k1).second;
            ans -= dis(x, x1);
          }
        }
        S.erase(Nd);
      }
    }
    scanf("\n");
  }
  return 0;
}
