#include <bits/stdc++.h>
using namespace std;
long long cnt[100001];
vector<pair<int, int> > g[100001];
long long w[100001];
long long dist[100001];
void init(int cur, int par) {
  dist[cur] = 1;
  for (pair<int, int> next : g[cur]) {
    if (next.first != par) {
      init(next.first, cur);
      dist[cur] += dist[next.first];
    }
  }
}
void go(int cur, int par) {
  for (pair<int, int> next : g[cur]) {
    if (next.first != par) {
      dist[cur] -= dist[next.first];
      dist[next.first] += dist[cur];
      go(next.first, cur);
      dist[next.first] -= dist[cur];
      dist[cur] += dist[next.first];
      int k = next.second;
      cnt[k] = (1LL * dist[next.first] * (dist[cur] - dist[next.first]));
    }
  }
}
int main(int argc, char const *argv[]) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    g[a].push_back(pair<int, int>(b, i));
    g[b].push_back(pair<int, int>(a, i));
    w[i] = c;
  }
  init(1, 1);
  go(1, 1);
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    ans += w[i] * cnt[i];
  }
  long long t = (1LL * n * (n - 1) * (n - 2)) / 6;
  int q;
  scanf("%d", &q);
  while (q--) {
    int k, x;
    scanf("%d%d", &k, &x);
    ans -= w[k] * cnt[k];
    w[k] = x;
    ans += w[k] * cnt[k];
    double ways = (double)ans / t;
    ways *= (n - 2);
    printf("%.15lf\n", ways);
  }
  return 0;
}
