#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG = 17;
long long n, m, k, u, v, x, y, t, a, b, ans;
int stt[MAXN], pos[MAXN], timer = 1;
int par[MAXN][LOG];
int h[MAXN];
long long H[MAXN];
vector<pair<int, int> > G[MAXN];
set<int> st;
void dfs(int node, int p) {
  pos[stt[node] = timer++] = node;
  h[node] = h[par[node][0] = p] + 1;
  for (int i = 1; i < LOG; i++) par[node][i] = par[par[node][i - 1]][i - 1];
  for (pair<int, int> pp : G[node])
    if (pp.first != p) {
      H[pp.first] = H[node] + pp.second;
      dfs(pp.first, node);
    }
}
int LCA(int x, int y) {
  if (h[x] > h[y]) swap(x, y);
  for (int i = 0; i < LOG; i++)
    if ((h[y] - h[x]) & (1 << i)) y = par[y][i];
  for (int i = LOG - 1; i >= 0; i--)
    if (par[x][i] != par[y][i]) {
      x = par[x][i];
      y = par[y][i];
    }
  if (x != y) x = par[x][0];
  return x;
}
long long dist(int u, int v) { return H[u] + H[v] - 2 * H[LCA(u, v)]; }
int prv(int x) {
  auto it = st.lower_bound(stt[x]);
  if (it == st.begin()) return pos[*st.rbegin()];
  return pos[*--it];
}
int nxt(int x) {
  auto it = ++st.lower_bound(stt[x]);
  if (it == st.end()) return pos[*st.begin()];
  return pos[*it];
}
void Add(int x) {
  st.insert(stt[x]);
  int u = prv(x), v = nxt(x);
  ans += dist(u, x) + dist(x, v) - dist(u, v);
}
void Rem(int x) {
  int u = prv(x), v = nxt(x);
  ans -= dist(u, x) + dist(x, v) - dist(u, v);
  st.erase(stt[x]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> u >> v >> x;
    G[u].push_back({v, x});
    G[v].push_back({u, x});
  }
  dfs(1, 1);
  char ch;
  cin >> m;
  while (m--) {
    cin >> ch;
    if (ch == '?')
      cout << (ans / 2) << '\n';
    else {
      cin >> v;
      if (ch == '+')
        Add(v);
      else
        Rem(v);
    }
  }
  return 0;
}
