#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
struct Edge {
  long long to;
  long long cost;
  long long from;
  Edge(long long t, long long c, long long f = -1) : to(t), cost(c), from(f) {
    ;
  }
};
long long n;
vector<vector<Edge> > G;
vector<int> subt;
long long count_visit(long long index, long long prev) {
  subt[index] = 1;
  for (auto e : G[index]) {
    if (e.to != prev) subt[index] += count_visit(e.to, index);
  }
  return subt[index];
}
long long sum_visit(long long index, long long prev) {
  long long ret = 0;
  for (auto e : G[index]) {
    if (e.to != prev) {
      ret += subt[e.to] * (n - subt[e.to]) * e.cost;
      ret += sum_visit(e.to, index);
    }
  }
  return ret;
}
int main() {
  cin >> n;
  G.resize(n);
  vector<Edge> edges(n - 1, Edge(0, 0, 0));
  for (long long i = 0; i < n - 1; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    edges[i] = Edge(b, c, a);
    G[a].push_back(Edge(b, c));
    G[b].push_back(Edge(a, c));
  }
  long long allcost;
  double allcase = n * (n - 1) / (1 * 2 * 3);
  subt.resize(n);
  count_visit(0, -1);
  allcost = sum_visit(0, -1);
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long r, w;
    cin >> r >> w;
    r--;
    long long temp = min(subt[edges[r].from], subt[edges[r].to]);
    allcost += (w - edges[r].cost) * temp * (n - temp);
    edges[r].cost = w;
    printf("%.10lf\n",
           (double)allcost * 2 * (3 * n - 6) / n / (n - 1) / (n - 2));
  }
  return 0;
}
