#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, maxbit = 21;
long long h[maxn], dt[maxn], p[maxn][maxbit], ans, tim, n, q, dis[maxn];
vector<pair<int, int>> adj[maxn];
set<pair<int, int>> s;
void dfs(int v, int par) {
  h[v] = h[par] + 1;
  dt[v] = tim++;
  p[v][0] = par;
  for (int i = 1; i < maxbit; i++) p[v][i] = p[p[v][i - 1]][i - 1];
  for (auto [u, w] : adj[v])
    if (u != par) dis[u] = dis[v] + w, dfs(u, v);
}
long long f_p(int v, int b) {
  for (int i = 0; i < maxbit; i++)
    if (b & (1 << i)) v = p[v][i];
  return v;
}
long long lca(int v, int u) {
  if (h[v] < h[u]) swap(v, u);
  v = f_p(v, h[v] - h[u]);
  if (u == v) return v;
  for (int i = 19; i > -1; i--)
    if (p[u][i] != p[v][i]) u = p[u][i], v = p[v][i];
  return p[v][0];
}
long long f_dis(int v, int u) { return dis[v] + dis[u] - 2 * dis[lca(v, u)]; }
long long f_lr(int v, bool lorr) {
  if (s.empty()) return v;
  auto res = s.upper_bound({dt[v], v});
  if (lorr) {
    if (res == s.begin()) res = s.end();
    res--;
  } else if (res == s.end())
    res = s.begin();
  return (*res).second;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0, v, u, w; i < n - 1; i++) {
    cin >> v >> u >> w;
    adj[v].push_back({u, w});
    adj[u].push_back({v, w});
  }
  dfs(1, 0);
  cin >> q;
  char ch;
  int v;
  while (q--) {
    cin >> ch;
    if (ch == '?')
      cout << ans / 2 << endl;
    else {
      cin >> v;
      if (ch == '+') {
        ans += -f_dis(f_lr(v, 1), f_lr(v, 0)) + f_dis(f_lr(v, 1), v) +
               f_dis(f_lr(v, 0), v);
        s.insert({dt[v], v});
      } else {
        s.erase({dt[v], v});
        ans -= -f_dis(f_lr(v, 1), f_lr(v, 0)) + f_dis(f_lr(v, 1), v) +
               f_dis(f_lr(v, 0), v);
      }
    }
  }
  return 0;
}
