#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10, MAXH = 27, INF = INT_MAX, MOD = 1e9 + 7;
int par[MAXN][MAXH], d[MAXN], pos = 0, id[MAXN];
long long sum[MAXN];
bool mark[MAXN];
vector<pair<int, int> > adj[MAXN];
void dfs(int x, int len) {
  mark[x] = true;
  d[x] = len;
  for (int i = 0; i < ((int)adj[x].size()); i++) {
    int v = adj[x][i].first, w = adj[x][i].second;
    if (mark[v]) continue;
    sum[v] = sum[x] + w;
    par[v][0] = x;
    dfs(v, len + 1);
  }
  id[x] = pos;
  pos++;
}
int getParent(int x, int k) {
  for (int i = 0; i < MAXH; i++)
    if ((1 << i) & k) x = par[x][i];
  return x;
}
int lca(int x, int y) {
  if (d[y] > d[x]) swap(x, y);
  x = getParent(x, d[x] - d[y]);
  if (x == y) return x;
  for (int i = MAXH - 1; i >= 0; i--)
    if (par[x][i] != par[y][i]) x = par[x][i], y = par[y][i];
  return par[x][0];
}
set<pair<int, int> > s;
set<pair<int, int> >::iterator prev(set<pair<int, int> >::iterator it) {
  if (it == s.begin())
    it = (--s.end());
  else
    it--;
  return it;
}
set<pair<int, int> >::iterator next(set<pair<int, int> >::iterator it) {
  if (it == (--s.end()))
    it = s.begin();
  else
    it++;
  return it;
}
long long calc(int x, int y) { return sum[x] + sum[y] - 2 * sum[lca(x, y)]; }
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    x--, y--;
    adj[x].push_back(make_pair(y, w));
    adj[y].push_back(make_pair(x, w));
  }
  par[0][0] = -1;
  dfs(0, 0);
  for (int i = 1; i < MAXH; i++)
    for (int j = 0; j < n; j++) par[j][i] = par[par[j][i - 1]][i - 1];
  int q;
  long long ans = 0;
  cin >> q;
  for (int i = 0; i < q; i++) {
    char ch;
    cin >> ch;
    if (ch == '+') {
      int x;
      cin >> x;
      x--;
      set<pair<int, int> >::iterator it = s.insert(make_pair(id[x], x)).first;
      if (((int)s.size()) == 1) continue;
      int a = prev(it)->second, b = next(it)->second;
      ans = ans + calc(x, a) + calc(x, b) - calc(a, b);
    } else if (ch == '-') {
      int x;
      cin >> x;
      x--;
      if (!((int)s.size())) continue;
      set<pair<int, int> >::iterator it = s.find(make_pair(id[x], x));
      int a = prev(it)->second, b = next(it)->second;
      ans = ans - (calc(x, a) + calc(x, b) - calc(a, b));
      s.erase(make_pair(id[x], x));
    } else
      cout << ans / 2 << endl;
  }
  return 0;
}
