#include <bits/stdc++.h>
using namespace std;
int N, Q;
vector<int> Ke[100000 + 1], Cost[100000 + 1], Id[100000 + 1];
int Count[100000 + 1], Pa[100000 + 1];
long long Tot = 0;
struct ENode {
  int Pa, Ch, C;
};
ENode Edge[100000 + 1];
void DFS(int Pos) {
  Count[Pos] = 1;
  for (int i = 0; i < int(Ke[Pos].size()); i++) {
    int v = Ke[Pos][i];
    if (Pa[Pos] != v) {
      Pa[v] = Pos;
      int h = Id[Pos][i];
      Edge[h].Pa = Pos;
      Edge[h].Ch = v;
      DFS(v);
      Count[Pos] += Count[v];
    }
  }
}
int main() {
  cin >> N;
  for (int i = 1; i < N; i++) {
    int X, Y, C;
    cin >> X >> Y >> C;
    Ke[X].push_back(Y);
    Ke[Y].push_back(X);
    Cost[X].push_back(C);
    Cost[Y].push_back(C);
    Id[X].push_back(i);
    Id[Y].push_back(i);
    Edge[i].Pa = X;
    Edge[i].Ch = Y;
    Edge[i].C = C;
  }
  DFS(1);
  for (int i = 1; i < N; i++) {
    Tot += ((long long)Edge[i].C) * ((long long)N - Count[Edge[i].Ch]) *
           ((long long)Count[Edge[i].Ch]);
  }
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    int X, C;
    cin >> X >> C;
    Tot -= ((long long)Edge[X].C) * ((long long)N - Count[Edge[X].Ch]) *
           ((long long)Count[Edge[X].Ch]);
    Edge[X].C = C;
    Tot += ((long long)Edge[X].C) * ((long long)N - Count[Edge[X].Ch]) *
           ((long long)Count[Edge[X].Ch]);
    printf("%.9lf\n", ((double(Tot)) / ((long long)N * (N - 1))) * 6);
  }
  return 0;
}
