#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];
int b[100001];
vector<int> neigh[100001];
long long l[100001];
long long leftNum[100001];
long long rightNum[100001];
void prop(int e, bool left) {
  int total = 1;
  int u = (left) ? b[e] : a[e];
  int v = (left) ? a[e] : b[e];
  for (int i = 0; i < neigh[v].size(); i++) {
    int f = neigh[v][i];
    int w = (a[f] == v) ? b[f] : a[f];
    if (w == u) continue;
    prop(f, b[f] == v);
    total += (b[f] == v) ? leftNum[f] : rightNum[f];
  }
  if (left) {
    leftNum[e] = total;
    rightNum[e] = n - total;
  } else {
    rightNum[e] = total;
    leftNum[e] = n - total;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    cin >> a[i] >> b[i] >> l[i];
    neigh[a[i]].push_back(i);
    neigh[b[i]].push_back(i);
    leftNum[i] = rightNum[i] = 0;
  }
  prop(1, false);
  prop(1, true);
  long long total = 0;
  for (int i = 1; i <= n - 1; i++) {
    total += l[i] * leftNum[i] * rightNum[i];
  }
  double mult = 6.0 / ((double)n * (n - 1));
  int q;
  cin >> q;
  for (int j = 1; j <= q; j++) {
    int r, w;
    cin >> r >> w;
    total -= leftNum[r] * rightNum[r] * (l[r] - w);
    l[r] = w;
    printf("%.10f\n", (double)total * mult);
  }
}
