#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > roads;
vector<int> edge[100005];
int par[100005], kids[100005], edge_w[100005];
void dfs(int u) {
  kids[u] = 1;
  for (int i = 0, v; i < edge[u].size(); i++) {
    v = edge[u][i];
    if (v == par[u]) {
      continue;
    }
    par[v] = u;
    dfs(v);
    kids[u] += kids[v];
  }
}
long long comb(int n, int k) {
  if (n < k) {
    return 0;
  }
  long long res = 1;
  for (int i = 0; i < k; i++) {
    res = res * (n - i);
    res = res / (i + 1);
  }
  return res;
}
long long cal(int n, int m) {
  long long val1 = n, val2 = m;
  long long res = val1 * comb(val2, 2);
  res = res + val2 * comb(val1, 2);
  return res;
}
int main() {
  int n, q, u, v, w;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d %d", &u, &v, &w);
    edge[u].push_back(v);
    edge[v].push_back(u);
    edge_w[i] = w;
    roads.push_back(make_pair(u, v));
  }
  dfs(1);
  long long den = comb(n, 3);
  double res = 0, prob;
  long long x, y;
  for (int i = 0; i < n - 1; i++) {
    u = roads[i].first;
    v = roads[i].second;
    if (v == par[u]) {
      swap(u, v);
    }
    x = kids[v];
    y = n - x;
    roads[i].first = x;
    roads[i].second = y;
    prob = (cal(x, y) * 1.0) / den;
    res += (prob * edge_w[i] * 2.0);
  }
  int id, wt;
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &id, &wt);
    id--;
    y = roads[id].second;
    x = roads[id].first;
    prob = (cal(x, y) * 1.0) / den;
    double curr = prob * 1.0 * (edge_w[id] - wt) * 2.0;
    edge_w[id] = wt;
    res -= curr;
    printf("%0.10lf\n", res);
  }
  return 0;
}
