#include <bits/stdc++.h>
using namespace std;
inline void OPEN(const string &s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
int n, q, a[100100], b[100100], l[100100], subtree[100100];
double w[100100];
vector<int> adj[100100];
void dfs(int v, int parent) {
  subtree[v] = 1;
  for (__typeof((adj[v]).begin()) it = (adj[v]).begin(); it != (adj[v]).end();
       it++) {
    int u = a[*it] + b[*it] - v;
    if (u == parent) continue;
    dfs(u, v);
    subtree[v] += subtree[u];
    double aa = subtree[u], bb = n - subtree[u], nn = n;
    w[*it] = (aa * bb * (aa + bb - 2.) * 6.) / nn / (nn - 1.) / (nn - 2.);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n - 1); ++i) {
    scanf("%d%d%d", &a[i], &b[i], &l[i]);
    adj[a[i]].push_back(i);
    adj[b[i]].push_back(i);
  }
  dfs(1, -1);
  double ans = 0;
  for (int i = 0; i < (n - 1); ++i) {
    ans += w[i] * l[i];
  }
  scanf("%d", &q);
  for (int i = 0; i < (q); ++i) {
    int r, s;
    scanf("%d%d", &r, &s);
    r--;
    ans -= w[r] * (l[r] - s);
    l[r] = s;
    printf("%.17lf\n", ans);
  }
  return 0;
}
