#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > pa[100007];
long long prs[100007];
int zjd[100007];
int n, q;
void dfs(long long la, long long th) {
  zjd[th] = 1;
  for (pair<int, int> i : pa[th])
    if (i.first != la) {
      dfs(th, i.first);
      zjd[th] += zjd[i.first];
      prs[i.second] = 1LL * zjd[i.first] * (n - zjd[i.first]);
    }
}
int a[100007], b[100007], w[100007];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d%d", a + i, b + i, w + i);
    a[i]--, b[i]--;
    pa[a[i]].push_back(make_pair(b[i], i));
    pa[b[i]].push_back(make_pair(a[i], i));
  }
  dfs(-1, 0);
  long long ans = 0;
  for (int i = 0; i < n; i++) ans += prs[i] * w[i];
  double cn3 = 6.00 / n / (n - 1);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int nag, wht;
    scanf("%d%d", &nag, &wht);
    nag--;
    ans -= 1LL * prs[nag] * (w[nag] - wht);
    w[nag] = wht;
    printf("%.13lf\n", cn3 * ans);
  }
  return 0;
}
