#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10;
int n, h[N], f[N], s[N];
vector<pair<int, int> > E[N];
void dfs(int i, int ff, int hh) {
  f[i] = ff;
  h[i] = hh;
  s[i] = 1;
  for (int j = 0; (j) < (int)(E[i].size()); (j)++)
    if (ff != E[i][j].first) {
      dfs(E[i][j].first, i, hh + 1);
      s[i] += s[E[i][j].first];
    }
}
int t[N][3];
double cc(int ss, int dd) {
  double ans = 0;
  ans += ss * 1.0 * (n - ss) * (n - ss - 1) * dd * 2 * 3;
  ans += ss * 1.0 * (ss - 1) * (n - ss) * dd * 2 * 3;
  ans /= n * 1.0 * (n - 1) * (n - 2);
  return ans;
}
int main(void) {
  cin >> n;
  for (int i = 0; (i) < (int)(n - 1); (i)++) {
    int x, y, d;
    cin >> x >> y >> d;
    E[x].push_back(make_pair(y, d));
    E[y].push_back(make_pair(x, d));
    t[i][0] = x;
    t[i][1] = y;
    t[i][2] = d;
  }
  dfs(1, -1, 0);
  double ans = 0;
  for (int i = 0; (i) < (int)(n - 1); (i)++) {
    if (h[t[i][0]] > h[t[i][1]]) swap(t[i][0], t[i][1]);
    int ss = s[t[i][1]];
    ans += cc(ss, t[i][2]);
  }
  int m;
  cin >> m;
  for (int i = 0; (i) < (int)(m); (i)++) {
    int j, k;
    cin >> j >> k;
    j--;
    int ss = s[t[j][1]];
    ans -= cc(ss, t[j][2]);
    t[j][2] = k;
    ans += cc(ss, t[j][2]);
    printf("%.10f\n", ans);
  }
}
