#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long fh = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= fh;
}
template <typename T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
long long n, q;
long long pt[100005], depth[100005];
long long u[100005], v[100005], w[100005];
vector<long long> g[100005];
void dfs(long long x, long long fa) {
  pt[x] = 1;
  for (long long i = 0; i < g[x].size(); i++)
    if (g[x][i] != fa) {
      depth[g[x][i]] = depth[x] + 1;
      dfs(g[x][i], x);
      pt[x] += pt[g[x][i]];
    }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i < n; i++) {
    cin >> u[i] >> v[i] >> w[i];
    g[u[i]].push_back(v[i]);
    g[v[i]].push_back(u[i]);
  }
  depth[1] = 1;
  dfs(1, -1);
  double ans = 0;
  for (long long i = 1; i < n; i++) {
    if (depth[u[i]] < depth[v[i]]) swap(u[i], v[i]);
    ans += (double)(pt[u[i]] * (n - pt[u[i]]) * (n - pt[u[i]] - 1) +
                    pt[u[i]] * (pt[u[i]] - 1) * (n - pt[u[i]])) *
           w[i] / (double)(n * (n - 1) * (n - 2) / 6);
  }
  cin >> q;
  for (long long i = 1; i <= q; i++) {
    long long a, b;
    cin >> a >> b;
    ans -= (double)(pt[u[a]] * (n - pt[u[a]]) * (n - pt[u[a]] - 1) +
                    pt[u[a]] * (pt[u[a]] - 1) * (n - pt[u[a]])) *
           w[a] / (double)(n * (n - 1) * (n - 2) / 6);
    w[a] = b;
    ans += (double)(pt[u[a]] * (n - pt[u[a]]) * (n - pt[u[a]] - 1) +
                    pt[u[a]] * (pt[u[a]] - 1) * (n - pt[u[a]])) *
           w[a] / (double)(n * (n - 1) * (n - 2) / 6);
    cout << fixed << setprecision(10) << ans << endl;
  }
  return 0;
}
