#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
void work();
void output() {
  int T = 1000;
  for (int cas = 0, END = (T); cas < END; cas++) {
    printf("%d\n", rand() * rand() * rand());
  }
}
int main() {
  work();
  return 0;
}
void scanf(int& x, char ch = 0) {
  while ((ch = getchar()) < '0' || ch > '9')
    ;
  x = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') x = x * 10 + ch - '0';
}
int e = 2;
const int E = 311111;
int first[E], nxt[E + E], vv[E + E], ww[E + E];
int fa[E], siz[E], idx[E], ep[E];
int n;
double tot;
double C2(double t) {
  if (t == 0 || t == 1) return 0;
  return t * (t - 1) / 2;
}
void dfs(int u, int f = 0) {
  fa[u] = f;
  siz[u] = 1;
  for (int e = first[u], v = vv[first[u]]; e; e = nxt[e], v = vv[e])
    if (v != f) {
      ep[idx[e]] = e;
      dfs(v, u);
      siz[u] += siz[v];
      double tt = C2(siz[v]) * (n - siz[v]) + C2(n - siz[v]) * siz[v];
      tot += tt * ww[e];
    }
}
void work() {
  while (scanf("%d", &n) == 1) {
    memset((first), 0, sizeof(first));
    tot = 0;
    for (int i = (1), END = (n - 1); i <= END; i++) {
      int u, v, l;
      scanf("%d%d%d", &u, &v, &l);
      idx[e] = idx[e + 1] = i;
      nxt[e] = first[u], vv[e] = v, ww[e] = l, first[u] = e++;
      nxt[e] = first[v], vv[e] = u, ww[e] = l, first[v] = e++;
    }
    dfs(1);
    double tim = n;
    tim = tim * (tim - 1) * (tim - 2) / 12.0;
    int q;
    scanf("%d", &q);
    while (q--) {
      int no, l;
      scanf("%d%d", &no, &l);
      int ee = ep[no];
      int v = vv[ee];
      double t =
          C2(siz[v]) * double(n - siz[v]) + C2(n - siz[v]) * double(siz[v]);
      if (t < 0)
        while (true)
          ;
      if (ww[ee] < l)
        while (true)
          ;
      tot -= (ww[ee] - l) * t;
      ww[ee] = l;
      printf("%.9lf\n", tot / tim);
    }
  }
}
