#include <bits/stdc++.h>
using namespace std;
long double Sum;
long double comb;
int N, Q;
long double nrPaths[100100];
int cost[100100];
int D[100100];
vector<pair<int, int> > A[100100];
int viz[100100];
void citire(void) {
  int a, b, c;
  cin >> N;
  for (int i = 1; i < N; i++) {
    cin >> a >> b >> c;
    A[a].push_back(make_pair(b, i));
    A[b].push_back(make_pair(a, i));
    cost[i] = c;
  }
}
inline void dinamica(int nod) {
  D[nod] = 1;
  viz[nod] = 1;
  for (int i = 0; i < A[nod].size(); i++)
    if (!viz[A[nod][i].first]) {
      dinamica(A[nod][i].first);
      nrPaths[A[nod][i].second] =
          1LL * D[A[nod][i].first] * (N - D[A[nod][i].first]);
      D[nod] += D[A[nod][i].first];
    }
}
void Rezolvare(void) {
  cout << fixed << setprecision(10);
  int a, b;
  long double dif = 0;
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    cin >> a >> b;
    dif = 1LL * (cost[a] - b) * nrPaths[a] * (N - 2);
    Sum -= dif;
    cost[a] = b;
    cout << (1.0 * Sum / comb) << "\n";
  }
}
int main() {
  citire();
  dinamica(1);
  for (int i = 1; i < N; i++) Sum += cost[i] * nrPaths[i];
  Sum *= N - 2;
  comb = (1.0 * N * (N - 1) * (N - 2)) / 6.0;
  Rezolvare();
}
