#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 10;
const int LOG = 20;
int ver[maxN], lo[maxN], hi[maxN];
int h[maxN];
long long w[maxN];
struct Node {
  int v, w;
};
vector<Node> g[maxN];
int n;
int T = 1;
int up[maxN][LOG];
void dfs(int x, int parent = 1, int height = 0, long long weight = 0) {
  ver[T] = x;
  lo[x] = T++;
  h[x] = height;
  w[x] = weight;
  up[x][0] = parent;
  for (int k = 1; k < LOG; ++k) {
    up[x][k] = up[up[x][k - 1]][k - 1];
  }
  for (auto node : g[x]) {
    if (node.v == parent) continue;
    dfs(node.v, x, height + 1, weight + node.w);
  }
  hi[x] = T - 1;
}
int jump(int x, int l) {
  for (int k = 0; k < LOG; ++k) {
    if (l & (1 << k)) {
      x = up[x][k];
    }
  }
  return x;
}
int lca(int u, int v) {
  if (h[u] > h[v]) swap(u, v);
  v = jump(v, h[v] - h[u]);
  if (u == v) return u;
  for (int k = LOG - 1; k >= 0; --k) {
    if (up[u][k] != up[v][k]) {
      u = up[u][k];
      v = up[v][k];
    }
  }
  return up[u][0];
}
bool p(int u, int v) { return lo[u] < lo[v] and hi[v] <= hi[u]; }
int ft[maxN];
void upd(int x, int v) {
  while (x <= n) {
    ft[x] += v;
    x += x & -x;
  }
}
int qry(int x) {
  int ans = 0;
  while (x > 0) {
    ans += ft[x];
    x -= x & -x;
  }
  return ans;
}
int sons(int x, bool b) { return qry(hi[x]) - qry(lo[x] - b); }
bool isSet[maxN];
int root;
long long mst;
void add(int x) {
  if (root == -1) {
    root = x;
  } else if (root == x) {
  } else if (p(root, x)) {
    if (!sons(x, 0)) {
      int anc = x;
      for (int k = LOG - 1; k >= 0; --k) {
        if (!(sons(up[anc][k], 1) - 1)) {
          anc = up[anc][k];
        }
      }
      anc = up[anc][0];
      mst += w[x] - w[anc];
    } else {
    }
  } else if (p(x, root)) {
    mst += w[root] - w[x];
    root = x;
  } else {
    int anc = lca(x, root);
    mst += w[x] + w[root] - 2 * w[anc];
    root = anc;
  }
}
int find(int x) {
  int l = 1, r = n;
  while (l < r) {
    int mid = l + (r - l) / 2;
    if (qry(mid) < x)
      l = mid + 1;
    else
      r = mid;
  }
  return ver[l];
}
void rem(int x) {
  bool gg = 0;
  if (x == root) {
    int ss = sons(root, 0);
    if (ss == 0) {
      root = -1;
    } else {
      int anc = lca(find(1), find(ss));
      mst -= w[anc] - w[root];
      root = anc;
    }
  } else if (sons(x, 0) == 0) {
    int anc = x;
    for (int k = LOG - 1; k >= 0; --k) {
      if (!(sons(up[anc][k], 1))) {
        anc = up[anc][k];
      }
    }
    anc = up[anc][0];
    mst -= w[x] - w[anc];
    if (anc == root and not isSet[root]) gg = 1;
  } else {
  }
  if (gg) rem(root);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  root = -1;
  dfs(1);
  int q;
  scanf("%d\n", &q);
  while (q--) {
    char ch = getchar();
    if (ch == '?') {
      getchar();
      printf("%lld\n", mst);
    } else {
      int x;
      scanf("%d\n", &x);
      isSet[x] ^= 1;
      if (ch == '+')
        upd(lo[x], 1), add(x);
      else
        upd(lo[x], -1), rem(x);
    }
  }
  return 0;
}
