#include <bits/stdc++.h>
using namespace std;
namespace fastIO1 {
inline char read() {
  static const int IN_LEN = 1000000;
  static char buf[IN_LEN], *s, *t;
  return (s == t               ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin),
          (s == t ? -1 : *s++) : *s++);
}
template <class T>
inline void read(T &x) {
  static bool iosig;
  static char c;
  for (iosig = false, c = read(); !isdigit(c); c = read()) {
    if (c == '-') iosig = true;
    if (c == -1) return;
  }
  for (x = 0; isdigit(c); c = read()) x = ((x + (x << 2)) << 1) + (c ^ '0');
  if (iosig) x = -x;
}
inline char readc(char &c) {
  for (c = read(); !isalpha(c) && !isdigit(c); c = read())
    if (c == -1) return 0;
}
const int OUT_LEN = 10000000;
char obuf[OUT_LEN], *ooh = obuf;
inline void print(char c) {
  if (ooh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf;
  *ooh++ = c;
}
template <class T>
inline void print(T x) {
  static int buf[30], cnt;
  if (x == 0)
    print('0');
  else {
    if (x < 0) print('-'), x = -x;
    for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48;
    while (cnt) print((char)buf[cnt--]);
  }
}
inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); }
}  // namespace fastIO1
namespace fastIO2 {
template <class T>
inline void read(T &x) {
  static bool iosig;
  static char c;
  for (iosig = false, c = getchar(); !isdigit(c); c = getchar()) {
    if (c == '-') iosig = true;
    if (c == -1) return;
  }
  for (x = 0; isdigit(c); c = getchar()) x = ((x + (x << 2)) << 1) + (c ^ '0');
  if (iosig) x = -x;
}
}  // namespace fastIO2
using namespace fastIO2;
int f[(100010)][20], ind, c[((100010) << 1)], E;
long long ans, dis[(100010)];
int n, m, fi[(100010)], ne[((100010) << 1)], b[((100010) << 1)], dfn[(100010)],
    dep[(100010)];
struct node {
  int x;
  friend bool operator<(node a, node b) { return dfn[a.x] < dfn[b.x]; }
};
set<node> S;
void add(int x, int y, int z) {
  ne[++E] = fi[x], fi[x] = E, b[E] = y, c[E] = z;
}
void dfs(int u, int pre) {
  f[u][0] = pre;
  for (int i = 1; i <= 19; i++) f[u][i] = f[f[u][i - 1]][i - 1];
  dfn[u] = ++ind;
  for (int i = fi[u]; i; i = ne[i]) {
    int v = b[i];
    if (v == pre) continue;
    dep[v] = dep[u] + 1;
    dis[v] = dis[u] + c[i];
    dfs(v, u);
  }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int k = dep[u] - dep[v];
  for (int i = 0; i <= 19; i++)
    if (k & (1 << i)) u = f[u][i];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--)
    if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
  return f[u][0];
}
long long getdis(int u, int v) { return dis[u] + dis[v] - 2 * dis[lca(u, v)]; }
void Insert(int x) {
  S.insert((node){x});
  if (S.size() == 1) return;
  int u, v;
  set<node>::iterator it = S.find((node){x});
  set<node>::iterator pre = it, suc = it;
  if (pre == S.begin())
    u = (*S.rbegin()).x;
  else
    pre--, u = (*pre).x;
  suc++;
  if (suc == S.end())
    v = (*S.begin()).x;
  else
    v = (*suc).x;
  ans = ans - getdis(u, v) + getdis(u, x) + getdis(x, v);
}
void Delete(int x) {
  if (S.size() == 1) {
    S.erase((node){x});
    return;
  }
  int u, v;
  set<node>::iterator it = S.find((node){x});
  set<node>::iterator pre = it, suc = it;
  if (pre == S.begin())
    u = (*S.rbegin()).x;
  else
    pre--, u = (*pre).x;
  suc++;
  if (suc == S.end())
    v = (*S.begin()).x;
  else
    v = (*suc).x;
  S.erase((node){x});
  ans = ans + getdis(u, v) - getdis(u, x) - getdis(x, v);
}
int main() {
  read(n);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    read(x), read(y), read(z);
    add(x, y, z), add(y, x, z);
  }
  dfs(1, 0), read(m);
  while (m--) {
    char op[3];
    int x;
    scanf("%s", op + 1);
    if (op[1] == '+')
      read(x), Insert(x);
    else if (op[1] == '-')
      read(x), Delete(x);
    else
      printf("%lld\n", ans / 2);
  }
}
