#include <bits/stdc++.h>
using namespace std;
const int N = 233333;
int n, m;
long long v[N];
vector<pair<int, int> > E[N];
vector<pair<pair<int, int>, int> > edges;
int dep[N], sz[N];
void dfs(int x, int f) {
  sz[x] = 1;
  for (int i = 0; i < E[x].size(); i++) {
    int y = E[x][i].first, c = E[x][i].second;
    if (y == f) continue;
    dep[y] = dep[x] + 1;
    dfs(y, x);
    sz[x] += sz[y];
  }
}
int main() {
  for (int i = 0; i < N; i++) v[i] = 1LL * i * (i - 1) * (i - 2) / 6;
  scanf("%d", &n);
  edges.clear();
  for (int i = 1; i <= n; i++) {
    E[i].clear();
  }
  for (int i = 1; i < n; i++) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    E[x].push_back(make_pair(y, c));
    E[y].push_back(make_pair(x, c));
    edges.push_back(make_pair(make_pair(x, y), c));
  }
  dep[1] = 0;
  dfs(1, 0);
  double ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int x = edges[i].first.first, y = edges[i].first.second,
        c = edges[i].second;
    if (dep[x] > dep[y]) swap(x, y);
    int a = sz[y], b = n - a;
    long long f = v[n] - v[a] - v[b];
    ans += 2.0 * c * f;
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int id, l;
    scanf("%d%d", &id, &l);
    id--;
    int x = edges[id].first.first, y = edges[id].first.second,
        c = edges[id].second;
    if (dep[x] > dep[y]) swap(x, y);
    int a = sz[y], b = n - a;
    long long f = v[n] - v[a] - v[b];
    c -= l;
    ans -= 2.0 * c * f;
    edges[id] = make_pair(edges[id].first, l);
    printf("%.12f\n", ans / v[n]);
  }
  return 0;
}
