#include <bits/stdc++.h>
using namespace std;
struct Road {
  int a, b, l;
  double p;
  int q;
};
int n, q;
vector<Road> road;
vector<vector<int>> g;
double ans;
int dfs(int num, int from = -1) {
  int res = 0;
  for (int i = 0; i < g[num].size(); i++) {
    int rd = g[num][i];
    int to = (rd < 0 ? road[-rd].a : road[rd].b);
    rd = abs(rd);
    if (rd == from) continue;
    road[rd].q = dfs(to, rd);
    res += road[rd].q;
  }
  res++;
  return res;
}
double calc(int q) {
  double res = 0.0;
  for (int i = 0; i < 2; i++) {
    q = n - q;
    res += (double)q * (n - q) * (n - q - 1) / n / (n - 1) / (n - 2);
  }
  return res * 6.0;
}
int main() {
  cin >> n;
  road.resize(n);
  g.resize(n + 1);
  for (int i = 1; i <= n - 1; i++) {
    cin >> road[i].a >> road[i].b >> road[i].l;
    g[road[i].a].push_back(i);
    g[road[i].b].push_back(-i);
  }
  dfs(1);
  for (int i = 1; i <= n - 1; i++) {
    road[i].p = calc(road[i].q);
    ans += road[i].p * road[i].l;
  }
  cin >> q;
  while (q--) {
    int r, w;
    cin >> r >> w;
    ans += road[r].p * (w - road[r].l);
    road[r].l = w;
    printf("%.8lf\n", ans);
  }
  return 0;
}
