#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool rd(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
template <class T>
inline void pt(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) pt(x / 10);
  putchar(x % 10 + '0');
}
const int N = 200010;
struct Edge {
  int to, num, nex;
} edge[N << 2];
int head[N], edgenum;
void add(int u, int v, int num) {
  Edge E = {v, num, head[u]};
  edge[edgenum] = E;
  head[u] = edgenum++;
}
int a[N], n, m, siz[N];
int dis[N];
long long l[N], r[N], all;
void dfs(int u, int fa) {
  siz[u] = 1;
  for (int i = head[u]; ~i; i = edge[i].nex) {
    int v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u);
    l[edge[i].num] = siz[v];
    r[edge[i].num] = n - siz[v];
    siz[u] += siz[v];
  }
}
void init() {
  memset(head, -1, sizeof head);
  edgenum = 0;
  for (int i = 1, u, v, d; i < n; i++) {
    rd(u);
    rd(v);
    rd(d);
    dis[i] = d;
    add(u, v, i);
    add(v, u, i);
  }
}
int main() {
  while (cin >> n) {
    init();
    dfs(1, 1);
    long long ans = 0;
    for (int i = 1; i < n; i++) {
      ans += l[i] * r[i] * dis[i];
    }
    int q;
    rd(q);
    while (q--) {
      int x, w;
      rd(x);
      rd(w);
      ans -= l[x] * r[x] * dis[x];
      dis[x] = w;
      ans += l[x] * r[x] * dis[x];
      printf("%.10f\n", (double)ans / ((long long)n * (n - 1)) * 6);
    }
  }
  return 0;
}
