#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline void smin(P &a, Q b) {
  if (b < a) a = b;
}
template <class P, class Q>
inline void smax(P &a, Q b) {
  if (a < b) a = b;
}
const int maxn = 100000 + 100;
int n, q;
int a[maxn], b[maxn], w[maxn];
vector<int> adj[maxn];
int sub[maxn];
double prob[maxn];
int dfs(int u, int par = -1, int pid = -1) {
  sub[u] = 1;
  for (int id : adj[u]) {
    int v = a[id] + b[id] - u;
    if (v != par) sub[u] += dfs(v, u, id);
  }
  if (pid != -1)
    prob[pid] = sub[u] * (long long)(sub[u] - 1) / 2 * (n - sub[u]) +
                sub[u] * (long long)(n - sub[u]) * (n - sub[u] - 1) / 2;
  return sub[u];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0, _n = (int)(n - 1); i < _n; i++) {
    cin >> a[i] >> b[i] >> w[i];
    a[i]--, b[i]--;
    adj[a[i]].push_back(i);
    adj[b[i]].push_back(i);
  }
  dfs(0);
  for (int i = 0, _n = (int)(n - 1); i < _n; i++)
    prob[i] /= n * (long long)(n - 1) * (n - 2) / 6;
  double ans = 0;
  for (int i = 0, _n = (int)(n - 1); i < _n; i++) ans += w[i] * prob[i];
  cout.setf(ios::fixed);
  cout.precision(8);
  cin >> q;
  for (int i = 0, _n = (int)(q); i < _n; i++) {
    int id, r;
    cin >> id >> r;
    id--;
    ans -= prob[id] * (w[id] - r);
    w[id] = r;
    cout << 2 * ans << endl;
  }
  return 0;
}
