#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 100 + 10, MAXLG = 25;
vector<int> ng[MAXN], w[MAXN];
long long dist[MAXN], ans;
int p[MAXN][MAXLG], dep[MAXN], num[MAXN], seen;
set<pair<int, int> > all;
void dfs(int x, int par, long long dis, int depth) {
  p[x][0] = par;
  dist[x] = dis;
  dep[x] = depth;
  num[x] = seen++;
  for (int i = 0; i < ng[x].size(); i++) {
    int u = ng[x][i];
    if (u != p[x][0]) dfs(u, x, (dist[x] + w[x][i]), depth + 1);
  }
}
int getParent(int x, int k) {
  for (int i = 0; i < MAXLG && x != -1; i++)
    if ((k >> i) & 1) x = p[x][i];
  return x;
}
int lca(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  if (dep[x] != dep[y]) y = getParent(y, dep[y] - dep[x]);
  if (x == y) return x;
  for (int i = MAXLG - 1; i >= 0; i--)
    if (p[x][i] != p[y][i]) {
      x = p[x][i];
      y = p[y][i];
    }
  return p[x][0];
}
set<pair<int, int> >::iterator next(set<pair<int, int> >::iterator it) {
  it++;
  if (it == all.end()) it = all.begin();
  return it;
}
set<pair<int, int> >::iterator prev(set<pair<int, int> >::iterator it) {
  if (it == all.begin()) it = all.end();
  it--;
  return it;
}
long long getDist(int x, int y) {
  return (dist[x] + dist[y] - dist[lca(x, y)] * 2);
}
void insert(int x) {
  all.insert(pair<int, int>(num[x], x));
  set<pair<int, int> >::iterator it = all.find(pair<int, int>(num[x], x));
  ans += getDist(it->second, next(it)->second);
  ans += getDist(it->second, prev(it)->second);
  ans -= getDist(prev(it)->second, next(it)->second);
}
void del(int x) {
  set<pair<int, int> >::iterator it = all.find(pair<int, int>(num[x], x));
  ans -= getDist(it->second, next(it)->second);
  ans -= getDist(it->second, prev(it)->second);
  ans += getDist(prev(it)->second, next(it)->second);
  all.erase(pair<int, int>(num[x], x));
}
int main() {
  int n, q;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    ng[x].push_back(y);
    ng[y].push_back(x);
    w[x].push_back(z);
    w[y].push_back(z);
  }
  dfs(0, -1, 0ll, 0);
  for (int i = 1; i < MAXLG; i++)
    for (int j = 0; j < n; j++) {
      if (p[j][i - 1] == -1)
        p[j][i] = -1;
      else
        p[j][i] = p[p[j][i - 1]][i - 1];
    }
  cin >> q;
  for (int i = 0; i < q; i++) {
    char c;
    cin >> c;
    if (c == '?')
      cout << (ans >> 1) << endl;
    else {
      int x;
      cin >> x;
      x--;
      if (c == '+')
        insert(x);
      else
        del(x);
    }
  }
  return 0;
}
