#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 5;
int n;
vector<int> G[N];
int kra[N][2];
int war[N], wag[N];
double suma;
long long dziel;
int dfs(int v) {
  wag[v] = 1;
  for (int i = 0; i < G[v].size(); i++)
    if (wag[G[v][i]] == 0) wag[v] += dfs(G[v][i]);
  return wag[v];
}
int main() {
  int a, b, c;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &a, &b, &c);
    kra[i][0] = a;
    kra[i][1] = b;
    war[i] = c;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  suma = 0;
  dziel = n * (long long)(n - 1) * (long long)(n - 2) / 6;
  dfs(1);
  for (int i = 1; i < n; i++) {
    if (wag[kra[i][0]] > wag[kra[i][1]]) swap(kra[i][0], kra[i][1]);
    suma +=
        (war[i] * (long long)wag[kra[i][0]] * (long long)(n - wag[kra[i][0]]) *
         (long long)(n - 2) / (double)dziel);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &a, &b);
    suma -=
        ((war[a] - b) * (long long)wag[kra[a][0]] *
         (long long)(n - wag[kra[a][0]]) * (long long)(n - 2) / (double)dziel);
    war[a] = b;
    printf("%.10f\n", suma);
  }
}
