#include <bits/stdc++.h>
using namespace std;
int l[222222], r[222222], w[222222], timein[222222], timeout[222222],
    cnt[222222];
vector<int> g[222222];
vector<int> W[222222];
bool used[222222];
int timer = 0, n;
long long answer = 0;
double ret;
long long ADD(int a, int b, int c) {
  return (long long)a * (long long)b * (long long)c;
}
void dfs(int v) {
  cnt[v] = 1;
  used[v] = false;
  ++timer;
  timein[v] = timer;
  for (int i = 0; i < g[v].size(); ++i) {
    int next = g[v][i];
    if (used[next] == false) continue;
    dfs(next);
    answer = answer + ADD(cnt[next], n - cnt[next], W[v][i]);
    cnt[v] += cnt[next];
  }
  ++timer;
  timeout[v] = timer;
}
int main() {
  scanf("%d\n", &n);
  for (int i = 1; i < n; ++i) scanf("%d %d %d\n", &l[i], &r[i], &w[i]);
  for (int i = 1; i < n; ++i) {
    g[l[i]].push_back(r[i]);
    g[r[i]].push_back(l[i]);
    W[l[i]].push_back(w[i]);
    W[r[i]].push_back(w[i]);
  }
  memset(used, true, sizeof(used));
  dfs(1);
  int m;
  double M = (double)(n) * (double)(n - 1) / 6.0;
  scanf("%d\n", &m);
  for (int i = 1; i <= m; ++i) {
    int d, d2;
    scanf("%d %d\n", &d, &d2);
    int LL = l[d], RR = r[d], WW = w[d] - d2;
    w[d] = d2;
    long long q1 = min(cnt[RR], cnt[LL]);
    long long q2 = n - q1;
    answer = answer - (long long)q1 * (long long)q2 * (long long)WW;
    printf("%.10lf\n", answer / M);
  }
  return 0;
}
