#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int a[N];
int b[N];
int len[N];
double p[N];
double tot;
vector<int> g[N];
vector<int> e[N];
int sz[N];
int used[N];
int dfs(int edge, int parent, int v) {
  int cnt = 1;
  int x = g[v].size();
  for (int j = 0; j < x; j++) {
    int next = g[v][j];
    int nextEdge = e[v][j];
    if (next != parent) {
      cnt += dfs(nextEdge, v, next);
    }
  }
  if (edge != -1) {
    sz[edge] = cnt;
  }
  return cnt;
}
int main() {
  cout << fixed;
  cout.precision(9);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    a[i] = x;
    b[i] = y;
    len[i] = z;
    g[x].push_back(y);
    g[y].push_back(x);
    e[x].push_back(i);
    e[y].push_back(i);
  }
  dfs(-1, -1, 0);
  double full = 1.0 * n * (n - 1) * (n - 2);
  for (int i = 0; i < n - 1; i++) {
    p[i] = full;
    int x;
    x = sz[i];
    p[i] -= 1.0 * x * (x - 1) * (x - 2);
    x = n - sz[i];
    p[i] -= 1.0 * x * (x - 1) * (x - 2);
    p[i] /= full;
  }
  tot = 0;
  for (int i = 0; i < n - 1; i++) {
    tot += 2 * len[i] * p[i];
  }
  int q;
  cin >> q;
  for (int t = 0; t < q; t++) {
    int r, w;
    cin >> r >> w;
    r--;
    tot -= 2 * (len[r] - w) * p[r];
    len[r] = w;
    cout << tot << "\n";
  }
  return 0;
}
