#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int n_ = 1e5 + 1000;
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
long long power(long long a, long long n) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long power(long long a, long long n, long long mod) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
long long n, m, dp[n_], u[n_], v[n_], w[n_], dp2[n_], sum = 0;
vector<pair<int, int> > e[n_];
void dfs(int u, int p = 0) {
  dp[u] = 1;
  for (auto it : e[u]) {
    int v = it.first;
    if (v == p) continue;
    int idx = it.second;
    dfs(v, u);
    dp[u] += dp[v];
    dp2[idx] = dp[v] * (n - dp[v]);
  }
}
int main() {
  cin >> n;
  for (int(i) = 0; (i) < (n - 1); (i)++) {
    cin >> u[i] >> v[i] >> w[i];
    e[--u[i]].push_back(pair<int, int>(--v[i], i));
    e[v[i]].push_back(pair<int, int>(u[i], i));
  }
  dfs(0);
  for (int(i) = 0; (i) < (n - 1); (i)++) sum += dp2[i] * w[i];
  long double tmp = n * (n - 1);
  cin >> m;
  while (m--) {
    int r, l;
    cin >> r >> l;
    sum -= dp2[--r] * w[r];
    w[r] = l;
    sum += dp2[r] * w[r];
    cout << fixed << setprecision((7));
    cout << 6.0 * sum / tmp << "\n";
  }
  return 0;
}
