#include <bits/stdc++.h>
using namespace std;
int rd() {
  int k = 0;
  char c = getchar();
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9') k = k * 10 + c - '0', c = getchar();
  return k;
}
const int N = 100001;
struct E {
  int v, w, nxt;
} e[N << 1];
int n, q, head[N], cnt, u, v, w, d[N], f[N], son[N], top[N], size[N], id[N];
long long sum, dis[N];
char c;
struct Cmp {
  bool operator()(int a, int b) { return id[a] < id[b]; }
};
set<int, Cmp> S;
set<int, Cmp>::iterator it, IT;
void add(int u, int v, int w) { e[++cnt] = (E){v, w, head[u]}, head[u] = cnt; }
void dfs1(int u, int fa) {
  d[u] = d[f[u] = fa] + 1, size[u] = 1;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) continue;
    dis[v] = dis[u] + e[i].w, dfs1(v, u), size[u] += size[v];
    if (size[son[u]] < size[v]) son[u] = v;
  }
}
void dfs2(int u, int t) {
  top[u] = t, id[u] = ++cnt;
  if (!son[u]) return;
  dfs2(son[u], t);
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v != f[u] && v != son[u]) dfs2(v, v);
  }
}
int LCA(int x, int y) {
  while (top[x] != top[y]) {
    if (d[top[x]] > d[top[y]])
      x = f[top[x]];
    else
      y = f[top[y]];
  }
  return d[x] < d[y] ? x : y;
}
long long D(int x, int y) { return dis[x] + dis[y] - 2 * dis[LCA(x, y)]; }
void Insert(int x) {
  if (S.empty()) {
    S.insert(x);
    return;
  }
  S.insert(x), it = S.find(x);
  if (it == S.begin())
    ++it, sum += D(x, *--S.end()) + D(x, *it) - D(*it, *--S.end());
  else if (it == --S.end())
    --it, sum += D(x, *S.begin()) + D(x, *it) - D(*it, *S.begin());
  else
    IT = it, ++IT, --it, sum += D(*it, x) + D(*IT, x) - D(*it, *IT);
}
void Delete(int x) {
  if (S.size() == 1) {
    S.clear();
    return;
  }
  it = S.find(x);
  if (it == S.begin())
    ++it, sum -= D(x, *--S.end()) + D(x, *it) - D(*it, *--S.end());
  else if (it == --S.end())
    --it, sum -= D(x, *S.begin()) + D(x, *it) - D(*it, *S.begin());
  else
    IT = it, ++IT, --it, sum -= D(x, *it) + D(x, *IT) - D(*it, *IT);
  S.erase(x);
}
int main() {
  n = rd();
  for (int i = 1; i < n; ++i)
    u = rd(), v = rd(), w = rd(), add(u, v, w), add(v, u, w);
  cnt = 0, dfs1(1, 0), dfs2(1, 1), q = rd();
  while (q--) {
    scanf("%c", &c);
    if (c == '+') Insert(rd());
    if (c == '-') Delete(rd());
    if (c == '?') printf("%lld\n", sum >> 1), getchar();
  }
  return 0;
}
