#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
const int MAX = 1000000;
const int inf = 1000 * 1000 * 1000;
const int p1 = 104393321, p2 = 104393329;
int cnt = 0, mark[MAX], pos[MAX], big[MAX], cmpr[MAX], n, m, POW[30];
long long dis[MAX], dp[MAX][21], tot = 0;
vector<int> adj[MAX], c[MAX];
vector<long long> d;
struct cmp {
  bool operator()(int x, int y) { return cmpr[x] < cmpr[y]; }
};
set<int, cmp> s;
set<int, cmp>::iterator it, b, nex;
long long DIS(int v, int u) {
  if (v == u) return 0;
  v = pos[v];
  u = pos[u];
  if (v > u) swap(u, v);
  int b = big[u - v + 1];
  long long lcp = min(dp[v][b], dp[u - POW[b] + 1][b]);
  return d[v] + d[u] - 2 * lcp;
}
void add(int v) {
  s.insert(v);
  it = s.find(v);
  if (it != s.begin()) {
    b = --it;
    ++it;
  } else
    b = --s.end();
  if (it != (--s.end())) {
    nex = ++it;
    --it;
  } else
    nex = s.begin();
  tot += -DIS(*b, *nex) + DIS(*b, *it) + DIS(*it, *nex);
}
void des(int v) {
  it = s.find(v);
  if (it != s.begin()) {
    b = --it;
    ++it;
  } else
    b = --s.end();
  if (it != --s.end()) {
    nex = ++it;
    --it;
  } else
    nex = s.begin();
  tot += DIS(*b, *nex) - DIS(*b, *it) - DIS(*it, *nex);
  s.erase(v);
}
void dfs(int v) {
  mark[v] = 1;
  cmpr[v] = cnt++;
  pos[v] = d.size();
  d.push_back(dis[v]);
  int u;
  for (int i = (0); i < int(adj[v].size()); ++i) {
    u = adj[v][i];
    if (!mark[u]) {
      dis[u] = dis[v] + c[v][i];
      dfs(u);
      d.push_back(dis[v]);
    }
  }
}
void preprocess() {
  int b = 0;
  for (int i = (1); i < int(d.size() + 1); ++i) {
    if (i >= POW[b + 1]) b++;
    big[i] = b;
  }
  for (int i = (0); i < int(d.size()); ++i) dp[i][0] = d[i];
  for (int j = (1); j < int(21); ++j)
    for (int i = (0); i < int(d.size()); ++i)
      if (i + POW[j] - 1 >= d.size())
        break;
      else
        dp[i][j] = min(dp[i][j - 1], dp[i + POW[j - 1]][j - 1]);
}
void PPP() {
  POW[0] = 1;
  for (int i = (1); i < int(21); ++i) POW[i] = 2 * POW[i - 1];
}
int main(int argc, char **argv) {
  ios::sync_with_stdio(0);
  cin >> n;
  PPP();
  for (int i = (0); i < int(n - 1); ++i) {
    int x, y, w;
    cin >> x >> y >> w;
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
    c[x].push_back(w);
    c[y].push_back(w);
  }
  dfs(0);
  preprocess();
  cin >> m;
  for (int i = (0); i < int(m); ++i) {
    char ch;
    int v;
    cin >> ch;
    if (ch == '?')
      cout << tot / 2 << endl;
    else if (ch == '+') {
      cin >> v;
      add(--v);
    } else {
      cin >> v;
      des(--v);
    }
  }
  return 0;
}
