#include <bits/stdc++.h>
using namespace std;
vector<int> adj[111111];
int u[111111], v[111111], c[111111];
int subtree[111111], pa[111111];
void dfs(int cur, int prev) {
  subtree[cur] = 1;
  pa[cur] = prev;
  for (int i = 0; i < adj[cur].size(); i++)
    if (adj[cur][i] != prev) {
      dfs(adj[cur][i], cur);
      subtree[cur] += subtree[adj[cur][i]];
    }
}
long long np3;
double get(int A, int B, int n) {
  long long Ap2 = A;
  Ap2 *= (A - 1);
  long long Bp2 = B;
  Bp2 *= (B - 1);
  long long num = A * Bp2 + B * Ap2;
  num *= 3;
  return double(num) / np3;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d%d", &u[i], &v[i], &c[i]);
    u[i]--;
    v[i]--;
    adj[u[i]].push_back(v[i]);
    adj[v[i]].push_back(u[i]);
  }
  dfs(0, -1);
  np3 = n;
  np3 *= (n - 1);
  np3 *= (n - 2);
  double ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int x = u[i], y = v[i];
    if (pa[x] == y) swap(x, y);
    int A = subtree[y];
    int B = n - A;
    ans += get(A, B, n) * c[i] * 2;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int r, w;
    scanf("%d", &r);
    scanf("%d", &w);
    r--;
    int x = u[r], y = v[r];
    if (pa[x] == y) swap(x, y);
    int A = subtree[y];
    int B = n - A;
    ans -= get(A, B, n) * c[r] * 2;
    c[r] = w;
    ans += get(A, B, n) * c[r] * 2;
    printf("%.10lf\n", ans);
  }
}
