#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct arc {
  int u, v, next;
};
class taskD {
  int n, cnt, q;
  int head[maxn], W[maxn];
  arc arcs[maxn << 1];
  double ans, all, pe[maxn];
  void read(int &x) {
    char ch;
    x = 0;
    while (!isdigit(ch = getchar()))
      ;
    do x = x * 10 + ch - '0';
    while (isdigit(ch = getchar()));
  }
  void addarc(int u, int v, int w) {
    arcs[cnt] = (arc){u, v, head[u]};
    head[u] = cnt++;
    arcs[cnt] = (arc){v, u, head[v]};
    head[v] = cnt++;
    W[cnt >> 1] = w;
  }
  int dfs(int u, int p, int id) {
    int ret = 1;
    for (int k = head[u]; k != -1; k = arcs[k].next) {
      int v = arcs[k].v;
      if (v != p) ret += dfs(v, u, k);
    }
    if (id != -1) {
      int pos = (id >> 1) + 1;
      double x = ret, y = n - ret;
      pe[pos] = (x * (x - 1) * y + y * (y - 1) * x) / all;
      ans += pe[pos] * W[pos];
    }
    return ret;
  }

 public:
  void solve() {
    while (~scanf("%d", &n)) {
      memset(head, -1, sizeof(int) * (n + 1));
      cnt = 0;
      all = (double)n * (n - 1) * (n - 2) / 6;
      ans = 0;
      for (int i = 1; i < n; i++) {
        int u, v, w;
        read(u);
        read(v);
        read(w);
        addarc(u, v, w);
      }
      dfs(1, -1, -1);
      read(q);
      while (q--) {
        int w, pos;
        read(pos);
        read(w);
        ans -= pe[pos] * (W[pos] - w);
        W[pos] = w;
        printf("%.10lf\n", ans);
      }
    }
  }
};
taskD solver;
int main() {
  solver.solve();
  return 0;
}
