#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double EPS = 0.000000001;
const double PI = 3.141592653589793;
const long long LLINF = 99999999999999999LL;
const int MAX_N = 100005;
const int MOD = 1000000007;
int N, M;
int A[MAX_N][3], cnt[MAX_N], lv[MAX_N];
vector<int> v[MAX_N];
long long a, b;
double ans;
bool vis[MAX_N];
void DFS(int x) {
  vis[x] = 1;
  cnt[x] = 1;
  for (int i = 0; i < (int)v[x].size(); ++i) {
    int y = v[x][i];
    if (vis[y]) continue;
    lv[y] = lv[x] + 1;
    DFS(y);
    cnt[x] += cnt[y];
  }
}
int main() {
  cin >> N;
  for (int i = 1; i < N; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    A[i][0] = x, A[i][1] = y, A[i][2] = c;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  lv[1] = 1;
  DFS(1);
  b = 1LL * (N - 2) * (N - 1) * N;
  for (int i = 1; i < N; ++i) {
    int x = A[i][0], y = A[i][1], c = A[i][2], cntX = 0, cntY = 0;
    long long t1 = 0, t2 = 0;
    if (lv[x] < lv[y]) {
      cntX = N - cnt[y];
      cntY = cnt[y];
    } else {
      cntX = cnt[x];
      cntY = N - cnt[x];
    }
    long long sum = 0;
    t1 = cntX;
    t2 = 1LL * (cntY - 1) * cntY;
    sum = 6LL * t1 * t2 * c;
    ans += (double)sum / b;
    t1 = 1LL * (cntX - 1) * cntX;
    t2 = cntY;
    sum = 6LL * t1 * t2 * c;
    ans += (double)sum / b;
  }
  cin >> M;
  for (int i = 1; i <= M; ++i) {
    int ind, x, y, c;
    int cntX, cntY;
    cin >> ind >> c;
    x = A[ind][0], y = A[ind][1];
    long long t1 = 0, t2 = 0;
    if (lv[x] < lv[y]) {
      cntX = N - cnt[y];
      cntY = cnt[y];
    } else {
      cntX = cnt[x];
      cntY = N - cnt[x];
    }
    long long sum1 = 0, sum2 = 0;
    t1 = cntX;
    t2 = 1LL * (cntY - 1) * cntY;
    sum1 += 6LL * t1 * t2 * c;
    sum2 += 6LL * t1 * t2 * A[ind][2];
    t1 = 1LL * (cntX - 1) * cntX;
    t2 = cntY;
    sum1 += 6LL * t1 * t2 * c;
    sum2 += 6LL * t1 * t2 * A[ind][2];
    ans = ans + (double)sum1 / b - (double)sum2 / b;
    A[ind][2] = c;
    printf("%.8lf\n", ans);
  }
  return 0;
}
