#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
using namespace std;
long long spf[301];
long long fac[301];
void sieve() {
  spf[1] = 1;
  for (long long i = 2; i < 301; i++) spf[i] = i;
  for (long long i = 4; i < 301; i += 2) spf[i] = 2;
  for (long long i = 3; i * i < 301; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j < 301; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
map<long long, long long> getfactor(long long a) {
  map<long long, long long> m;
  while (a > 1) {
    m[spf[a]]++;
    a /= spf[a];
  }
  return m;
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long inverse(long long a, long long p) { return power(a, p - 2, p); }
long long ncr(long long n, long long r, long long p) {
  if (r > n) return 0;
  if (r == 0) return 1;
  return (fac[n] * inverse(fac[r], p) % p * inverse(fac[n - r], p) % p) % p;
}
long long ret(long long a) { return (a * (a - 1)); }
map<pair<long long, long long>, long long> m;
map<long long, long long> m2;
long long n;
vector<long long> v[100001];
long long dfs(long long cur, long long par) {
  long long sum = 0;
  for (auto it : v[cur]) {
    if (it != par) {
      long long temp = dfs(it, cur);
      sum += temp;
      m2[m[make_pair(cur, it)]] =
          (temp * (ret(n - temp))) + (n - temp) * (ret(temp));
    }
  }
  sum++;
  return sum;
}
void solve() {
  cin >> n;
  long long val[n];
  for (long long i = 1; i <= n - 1; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    m[make_pair(a, b)] = i;
    m[make_pair(b, a)] = i;
    val[i] = c;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1, 0);
  long double ans = 0;
  long double temp = ((n * (n - 1)) * (n - 2)) / 6;
  for (auto it : m2) {
    ans += (val[it.first] * it.second) / temp;
  }
  long long q;
  cin >> q;
  for (long long i = 1; i <= q; i++) {
    long long r, w;
    cin >> r >> w;
    ans -= (m2[r] * val[r]) / temp;
    ans += (m2[r] * w) / temp;
    val[r] = w;
    cout << fixed << setprecision(10) << ans << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long test = 1;
  while (test--) {
    solve();
  }
}
