#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 9;
const int lg = 20;
set<int> Que;
vector<pair<int, int> > al[Maxn];
int h[Maxn], st[Maxn], ts, par[Maxn][lg];
long long dep[Maxn];
int st_to_id[Maxn];
void dfs(int v, int p = -1, long long depth = 0) {
  if (p + 1) h[v] = h[p] + 1;
  dep[v] = depth;
  st[v] = ts;
  st_to_id[ts++] = v;
  par[v][0] = p;
  for (int i = 1; i < lg; ++i)
    if (par[v][i - 1] + 1)
      par[v][i] = par[par[v][i - 1]][i - 1];
    else
      par[v][i] = -1;
  for (int i = 0; i < al[v].size(); i++) {
    int u = al[v][i].first, w = al[v][i].second;
    if (u == p) continue;
    dfs(u, v, depth + w);
  }
  return;
}
int go_up(int v, int x) {
  for (int i = lg - 1; i + 1; --i)
    if ((1 << i) & x) v = par[v][i];
  return v;
}
int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  u = go_up(u, h[u] - h[v]);
  if (u == v) return v;
  for (int i = lg - 1; i + 1; --i)
    if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
  return par[v][0];
}
long long get_dis(int u, int v) { return dep[u] + dep[v] - 2 * dep[lca(u, v)]; }
long long pls(int v) {
  if (!Que.size()) return 0;
  set<int>::iterator ed = Que.end(), bg = Que.begin();
  ed--;
  set<int>::iterator pl = Que.lower_bound(st[v]);
  if (pl == bg || pl == Que.end())
    return get_dis(v, st_to_id[*bg]) + get_dis(v, st_to_id[*ed]) -
           get_dis(st_to_id[*ed], st_to_id[*bg]);
  set<int>::iterator low = pl;
  low--;
  return get_dis(v, st_to_id[*low]) + get_dis(v, st_to_id[*pl]) -
         get_dis(st_to_id[*pl], st_to_id[*low]);
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    al[--u].push_back(make_pair(--v, w));
    al[v].push_back(make_pair(u, w));
  }
  long long ans = 0;
  dfs(0);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    char ch;
    cin >> ch;
    if (ch == '+') {
      int v;
      cin >> v;
      --v;
      ans += pls(v);
      Que.insert(st[v]);
    } else if (ch == '-') {
      int v;
      cin >> v;
      --v;
      Que.erase(st[v]);
      ans -= pls(v);
    } else {
      cout << ans / 2 << "\n";
    }
  }
  return 0;
}
