#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long res, ok = 1;
  char ch;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') ok = -1;
  res = ch - '0';
  for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
    res = res * 10 + ch - '0';
  return res * ok;
}
long long n, num[100005], q, tot, last[100005];
long long ans;
double tat;
struct edge {
  long long u, v, w, last;
} a[200005];
inline void link(int u, int v, int w) {
  tot++;
  a[tot].u = u;
  a[tot].v = v;
  a[tot].w = w;
  a[tot].last = last[u];
  last[u] = tot;
}
inline void dfs(int x, int fa) {
  num[x] = 1;
  for (int i = last[x]; i; i = a[i].last) {
    int v = a[i].v;
    if (v != fa) {
      dfs(v, x);
      num[x] += num[v];
    }
  }
}
int main() {
  n = read();
  tat = 3 * 1.0 / (n * (n - 1));
  for (int i = 1; i < n; i++) {
    int u, v, w;
    u = read();
    v = read();
    w = read();
    link(u, v, w);
    link(v, u, w);
  }
  dfs(1, 0);
  for (int i = 1; i <= tot; i++) {
    long long qwer = min(num[a[i].u], num[a[i].v]);
    qwer = qwer * (n - qwer);
    ans += qwer * a[i].w;
  }
  q = read();
  for (int j = 1; j <= q; j++) {
    long long x, d;
    x = read();
    d = read();
    for (int i = x * 2 - 1; i <= x * 2; i++) {
      long long qwer = min(num[a[i].u], num[a[i].v]);
      qwer = qwer * (n - qwer);
      ans -= qwer * (a[i].w - d);
      a[i].w = d;
    }
    printf("%.10lf\n", (double)ans * tat);
  }
  return 0;
}
