#include <bits/stdc++.h>
using namespace std;
int fs() {
  int x = 0;
  char c;
  c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while ('0' <= c && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x;
}
void pps(const char *s) {
  int i;
  for (i = 0; s[i] != '\0'; i++) {
    putchar(s[i]);
  }
}
void _ppd(int a) {
  if (a == 0) return;
  _ppd(a / 10);
  putchar(a % 10 + '0');
}
void ppd(int a) {
  if (a == 0) {
    putchar('0');
    return;
  }
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  _ppd(a);
}
void _pplld(long long a) {
  if (a == 0) return;
  _pplld(a / 10);
  putchar(a % 10 + '0');
}
void pplld(long long a) {
  if (a == 0) {
    putchar('0');
    return;
  }
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  _pplld(a);
}
int ggs(char *s) {
  int x = 0;
  char c = getchar();
  while (!('a' <= c && c <= 'z') && c != -1) c = getchar();
  while ('a' <= c && c <= 'z') {
    s[x++] = c;
    c = getchar();
  }
  s[x] = '\0';
  return x;
}
int fsn() {
  int x = 0;
  char c;
  c = getchar();
  while (!('0' <= c && c <= '9' || c == '-')) c = getchar();
  int neg = 0;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return (neg == 0 ? x : -x);
}
int n;
vector<pair<int, int> > gr[100010];
double hag[100010];
long long we[100010];
int sz[100010];
long long poop;
int dfs(int c, int p) {
  int i, z = gr[c].size();
  long long ret = 1;
  for (i = 0; i < z; i++) {
    if (gr[c][i].first != p) {
      long long opar = n, neeche = 0;
      neeche = dfs(gr[c][i].first, c);
      opar = n - neeche;
      hag[gr[c][i].second] =
          (opar * (opar - 1) / 2) * (neeche) / (double)poop +
          (neeche * (neeche - 1) / 2) * (double)opar / (double)poop;
      hag[gr[c][i].second] *= 2.0;
      ret += neeche;
    }
  }
  return (int)ret;
}
int main() {
  int i, j;
  n = fs();
  poop = (long long)n * ((long long)n - 1) * ((long long)n - 2) / (long long)6;
  for (i = 0; i < n - 1; i++) {
    int x, y, w;
    x = fs();
    y = fs();
    w = fs();
    we[i] = w;
    gr[x].push_back(make_pair(y, i));
    gr[y].push_back(make_pair(x, i));
  }
  dfs(1, -1);
  double ans = 0;
  for (i = 0; i < n - 1; i++) {
    ans += (double)hag[i] * we[i];
  }
  int q;
  q = fs();
  while (q--) {
    int x, nw;
    x = fs();
    nw = fs();
    x--;
    ans -= we[x] * hag[x];
    we[x] = nw;
    ans += we[x] * hag[x];
    printf("%.15lf\n", (double)ans);
  }
  return 0;
}
