#include <bits/stdc++.h>
using namespace std;
struct node {
  int k;
  int len;
  int edge;
};
node *a[200000];
int b[200000];
int b2[200000];
int dp[200000];
int dp2[200000];
int sizea = 0;
int dfs(int p) {
  dp[p] = 1;
  dp2[p] = 1;
  for (int i = 1; i < b[p]; i++)
    if (dp[(a[p] + i)->k] == 0) {
      dp2[p] += dfs((a[p] + i)->k);
    }
  return dp2[p];
}
int main() {
  int n;
  cin >> n;
  int edg[n][3];
  for (int i = 1; i < n; i++) {
    int m, m2, l;
    cin >> m >> m2 >> l;
    edg[i][0] = m;
    edg[i][1] = m2;
    edg[i][2] = l;
    b2[m]++;
    b2[m2]++;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = (node *)malloc((b2[i] + 1) * sizeof(node));
    (a[i] + 0)->k = i;
    (a[i] + 0)->len = 0;
    b[i] = 1;
  }
  for (int i = 1; i < n; i++) {
    int m = edg[i][0], m2 = edg[i][1], l = edg[i][2];
    (a[m] + b[m])->k = m2;
    (a[m2] + b[m2])->k = m;
    (a[m] + b[m])->len = l;
    (a[m2] + b[m2])->len = l;
    (a[m] + b[m])->edge = i;
    (a[m2] + b[m2])->edge = i;
    b[m]++;
    b[m2]++;
  }
  int t;
  cin >> t;
  for (int i = 1; i <= n; i++) dp2[i] = 0;
  dp2[1] = dfs(1);
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    int f = min(dp2[edg[i][0]], dp2[edg[i][1]]);
    sum += (2 * (long long)edg[i][2] * (long long)f * (long long)(n - f));
  }
  while (t--) {
    int z1, z2;
    cin >> z1 >> z2;
    int diff = edg[z1][2] - z2;
    edg[z1][2] = z2;
    int f = min(dp2[edg[z1][0]], dp2[edg[z1][1]]);
    sum -= (long long)(2 * (long long)diff * (long long)f * (long long)(n - f));
    cout << setprecision(11)
         << (long double)(3 * sum) / ((long double)n * (long double)(n - 1))
         << endl;
  }
  return 0;
}
