#include <bits/stdc++.h>
using namespace std;
const int maxn = 210000;
int head[maxn], ver[maxn], nt[maxn];
int l[maxn], r[maxn], edge[maxn];
int cnt[maxn], vi[maxn];
int dp[maxn];
bool ha[maxn];
int tot = 1;
double ans = 0;
long long num = 0;
int n;
void add(int x, int y, int z, int pos) {
  ver[++tot] = y, edge[tot] = z;
  nt[tot] = head[x], head[x] = tot;
  cnt[tot] = pos;
  vi[pos] = z;
}
void dfs(int x) {
  ha[x] = true;
  dp[x] = 1;
  for (int i = head[x]; i; i = nt[i]) {
    int y = ver[i], z = edge[i];
    int pos = cnt[i];
    if (ha[y]) continue;
    dfs(y);
    dp[x] += dp[y];
    l[pos] = dp[y], r[pos] = n - dp[y];
    ans += z * 1.0 * 2 / (double)num *
           ((l[pos] * 1.0 * (l[pos] - 1) * r[pos]) +
            (l[pos] * 1.0 * r[pos] * (r[pos] - 1))) *
           3.0;
  }
  return;
}
double ask(int pos, int wi) {
  double a = l[pos], b = r[pos];
  double ans = (wi - vi[pos]) * 1.0 * 2 / (double)num *
               (a * b * (b - 1) + b * a * (a - 1)) * 3.0;
  vi[pos] = wi;
  return ans;
}
int main(void) {
  scanf("%d", &n);
  int x, y, z;
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z, i);
    add(y, x, z, i);
  }
  num = (long long)n * ((long long)n - 1) * (n - 2);
  dfs(1);
  int q;
  int pos, vi;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &pos, &vi);
    ans += ask(pos, vi);
    printf("%.10f\n", ans);
  }
  return 0;
}
