#include <bits/stdc++.h>
using namespace std;
long long getLL() {
  long long ret = 0;
  char c;
  while (1) {
    c = getchar();
    if (c >= '0' && c <= '9') break;
  }
  while (1) {
    ret = ret * 10 + c - '0';
    c = getchar();
    if (c < '0' || c > '9') break;
  }
  return ret;
}
int getInt() {
  int ret = 0;
  char c;
  while (1) {
    c = getchar();
    if (c >= '0' && c <= '9') break;
  }
  while (1) {
    ret = ret * 10 + c - '0';
    c = getchar();
    if (c < '0' || c > '9') break;
  }
  return ret;
}
int v[1020304 * 2], __sro__yy__orz__[1020304 * 2], h[1020304], who[1020304],
    w[1020304], tot;
void add(int b, int e, int wei, int num) {
  v[++tot] = e;
  __sro__yy__orz__[tot] = h[b];
  h[b] = tot;
  w[tot] = wei;
  who[tot] = num;
  v[++tot] = b;
  __sro__yy__orz__[tot] = h[e];
  h[e] = tot;
  w[tot] = wei;
  who[tot] = num;
}
long double calc(long long n) { return n * (n - 1) / 2.0; }
long long All = 0;
long double calcTri(long long x, long long y) {
  return (calc(x) * y + x * calc(y)) / All;
}
int n, Q, s[1020304], q[1020304], vis[1020304], edge[1020304], node[1020304],
    curWei[1020304], father[1020304];
int main() {
  cin >> n;
  memset(h, tot = 0, sizeof(h));
  for (int i = 1; i <= n - 1; ++i) {
    int b, e, wei;
    scanf("%d%d%d", &b, &e, &wei);
    add(b, e, wei, i);
    curWei[i] = wei;
  }
  All = (long long)n * (n - 1) * (n - 2) / 6;
  int hd = 0, tl = 1;
  memset(vis, 0, sizeof(vis));
  vis[q[1] = 1] = true;
  while (hd < tl) {
    int vex = q[++hd];
    for (int z = h[vex]; z; z = __sro__yy__orz__[z])
      if (!vis[v[z]]) {
        vis[q[++tl] = v[z]] = true;
        father[v[z]] = vex;
        node[who[z]] = v[z];
        edge[v[z]] = who[z];
      }
  }
  for (int i = tl; i >= 1; --i) {
    int vex = q[i];
    s[vex] = 1;
    for (int z = h[vex]; z; z = __sro__yy__orz__[z])
      if (v[z] != father[vex]) {
        s[vex] += s[v[z]];
      }
  }
  long double ans = 0;
  for (int i = 2; i <= n; ++i) {
    ans += calcTri(s[i], n - s[i]) * curWei[edge[i]];
  }
  cin >> Q;
  for (int QQQ = 1; QQQ <= Q; ++QQQ) {
    int x, y;
    scanf("%d%d", &x, &y);
    int diff = y - curWei[x];
    curWei[x] = y;
    ans += calcTri(s[node[x]], n - s[node[x]]) * diff;
    printf("%.12f\n", (double)ans * 2);
  }
  return 0;
}
