#include <bits/stdc++.h>
using namespace std;
const int maxm = 1e6 + 9;
const int maxn = 3e5 + 9;
const int mod = 1e9 + 7;
const long long inf = 1e18;
const int base = 131;
const double eps = 1e-4;
int n, q;
struct Edge {
  int v, f, w, id;
} edge[maxn];
int w[maxn];
int last[maxn], cnt = 0;
double ans;
int f[maxn], g[maxn], sze[maxn];
inline int read() {
  int a = 1, b = 0;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') a = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    b = (b << 3) + (b << 1) + c - '0';
    c = getchar();
  }
  return a * b;
}
inline void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
void add(int x, int y, int z, int xyz) {
  edge[++cnt].v = y;
  edge[cnt].w = z;
  edge[cnt].f = last[x];
  edge[cnt].id = xyz;
  last[x] = cnt;
}
void dfs(int u, int fa) {
  sze[u] = 1;
  for (int i = last[u]; i; i = edge[i].f) {
    int v = edge[i].v;
    if (v == fa) continue;
    dfs(v, u);
    sze[u] += sze[v];
    f[edge[i].id] = sze[v];
    g[edge[i].id] = n - sze[v];
  }
}
int main() {
  int u, v;
  n = read();
  for (int i = (1); i <= (n - 1); ++i) {
    u = read(), v = read(), w[i] = read();
    add(u, v, w[i], i);
    add(v, u, w[i], i);
  }
  dfs(1, 0);
  long long N = 1LL * (n - 2) * (n - 1) * n / 6;
  for (int i = (1); i <= (n); ++i) {
    ans += (((double)(f[i] - 1) * f[i] * g[i] * w[i] +
             (double)(g[i] - 1) * g[i] * f[i] * w[i]) *
            1.0) /
           N * 1.0;
  }
  q = read();
  while (q--) {
    u = read(), v = read();
    ans -= (((double)(f[u] - 1) * f[u] * g[u] * (w[u] - v) * 1.0 +
             (double)(g[u] - 1) * g[u] * f[u] * (w[u] - v)) *
            1.0) /
           N * 1.0;
    printf("%.9f\n", (double)ans);
    w[u] = v;
  }
  return 0;
}
