#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
template <class T>
inline bool read(T &n) {
  T x = 0, tmp = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
  if (c == EOF) return false;
  if (c == '-') c = getchar(), tmp = -1;
  while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
  n = x * tmp;
  return true;
}
template <class T>
inline void write(T n) {
  if (n < 0) {
    putchar('-');
    n = -n;
  }
  int len = 0, data[20];
  while (n) {
    data[len++] = n % 10;
    n /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
}
const int MAXN = 100010;
int n, m;
int a[MAXN], b[MAXN], len[MAXN], cnt[MAXN];
vector<int> g[MAXN];
int dfs(int u, int fa) {
  cnt[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    if (g[u][i] == fa) continue;
    dfs(g[u][i], u);
    cnt[u] += cnt[g[u][i]];
  }
  return cnt[u];
}
int main() {
  while (read(n)) {
    for (int i = 0; i < n; ++i) g[i].clear();
    for (int i = 0; i < n - 1; i++) {
      read(a[i]), read(b[i]), read(len[i]);
      a[i]--;
      b[i]--;
      g[a[i]].push_back(b[i]);
      g[b[i]].push_back(a[i]);
    }
    dfs(0, -1);
    double C[MAXN];
    for (int i = 0; i < n - 1; i++) {
      long long v = min(cnt[a[i]], cnt[b[i]]);
      C[i] = (double)v * (n - v) * (n - 2);
    }
    double res = 0;
    for (int i = 0; i < n - 1; i++) {
      res += C[i] * len[i];
    }
    double x = (double)n * (n - 1) * (n - 2) / 6;
    read(m);
    for (int i = 0; i < m; i++) {
      int r, w;
      read(r), read(w);
      r--;
      res -= C[r] * (len[r] - w);
      len[r] = w;
      printf("%.10lf\n", res / x);
    }
  }
  return 0;
}
