#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline bool mmin(P &a, Q b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class P, class Q>
inline bool mmax(P &a, Q b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int MAXn = 100 * 1000, lg = 20;
int n;
vector<pair<int, int> > adj[MAXn];
int par[lg][MAXn], dep[MAXn];
long long w[lg][MAXn], ans;
int cur = 0;
int tar[MAXn];
void DFS(int x) {
  tar[x] = cur++;
  for (int i = 0; i < ((int)adj[x].size()); ++i) {
    int y = adj[x][i].first;
    if (par[0][x] != y) {
      dep[y] = dep[x] + 1;
      par[0][y] = x;
      w[0][y] = adj[x][i].second;
      DFS(y);
    }
  }
}
inline long long dis(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  long long ret = 0;
  for (int i = lg - 1; i >= 0; --i)
    if (dep[x] - (1 << i) >= dep[y]) {
      ret += w[i][x];
      x = par[i][x];
    }
  if (x == y) return ret;
  for (int i = lg - 1; i >= 0; --i)
    if (par[i][x] != par[i][y]) {
      ret += w[i][x] + w[i][y];
      x = par[i][x];
      y = par[i][y];
    }
  ret += w[0][x] + w[0][y];
  return ret;
}
struct cmp {
  bool operator()(const int &x, const int &y) { return tar[x] < tar[y]; }
};
set<int, cmp> st;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int x, y, w;
    cin >> x >> y >> w;
    --x;
    --y;
    adj[x].push_back(pair<int, int>(y, w));
    adj[y].push_back(pair<int, int>(x, w));
  }
  DFS(0);
  for (int j = 1; j < lg; ++j)
    for (int i = 0; i < n; ++i) {
      par[j][i] = par[j - 1][par[j - 1][i]];
      w[j][i] = w[j - 1][i] + w[j - 1][par[j - 1][i]];
    }
  set<int, cmp>::iterator it1, it2;
  int nq;
  cin >> nq;
  while (nq--) {
    char c;
    int x;
    cin >> c;
    if (c == '+') {
      cin >> x;
      --x;
      it1 = st.insert(x).first;
      int y, z;
      it2 = it1 == st.begin() ? st.end() : it1;
      --it2;
      y = *it2;
      it2 = it1;
      ++it2;
      it2 = it2 == st.end() ? st.begin() : it2;
      z = *it2;
      ans += dis(x, y) + dis(x, z) - dis(y, z);
    } else if (c == '-') {
      cin >> x;
      --x;
      it1 = st.find(x);
      int y, z;
      it2 = it1 == st.begin() ? st.end() : it1;
      --it2;
      y = *it2;
      it2 = it1;
      ++it2;
      it2 = it2 == st.end() ? st.begin() : it2;
      z = *it2;
      ans -= dis(x, y) + dis(x, z) - dis(y, z);
      st.erase(it1);
    } else
      cout << ans / 2 << '\n';
  }
  return 0;
}
