#include <bits/stdc++.h>
using namespace std;
int siz[100010 + 1], edx[100010 + 1], edy[100010 + 1], wt[100010 + 1];
vector<int> u[100010 + 1];
void mkTree(int x, int p) {
  siz[x] = 1;
  for (int i = 0; i < u[x].size(); i++)
    if (u[x][i] != p) {
      mkTree(u[x][i], x);
      siz[x] += siz[u[x][i]];
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(8);
  int n, q, x, a, b;
  long long sol = 0LL;
  double fin = 0.0;
  cin >> n;
  for (int i = 0; i < (n - 1); i++) {
    cin >> edx[i] >> edy[i] >> wt[i];
    u[edx[i]].push_back(edy[i]);
    u[edy[i]].push_back(edx[i]);
  }
  mkTree(1, 1);
  for (int i = 0; i < (n - 1); i++) {
    x = min(siz[edx[i]], siz[edy[i]]);
    sol += ((long long)(n - x) * x * wt[i]);
  }
  cin >> q;
  while (q--) {
    cin >> a >> b;
    x = min(siz[edx[a - 1]], siz[edy[a - 1]]);
    sol += ((long long)(n - x) * x * (b - wt[a - 1]));
    wt[a - 1] = b;
    fin = (double)(n - 2) * sol;
    cout << fixed << (double)(6.0 * fin) / ((double)n * (n - 1) * (n - 2))
         << "\n";
  }
  return 0;
}
