#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
struct edge {
  int u, v, id;
};
long long ci[maxn];
int w[maxn];
vector<edge> g[maxn];
int n;
void add_edge(int u, int v, int id) { g[u].push_back((edge){u, v, id}); }
vector<int> cmp;
int number1[maxn];
void dfs1(int u, int fa) {
  number1[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    edge& e = g[u][i];
    if (e.v != fa) {
      dfs1(e.v, u);
      number1[u] += number1[e.v];
      ci[e.id] = number1[e.v];
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d %d %d", &u, &v, &w[i]);
    add_edge(u, v, i);
    add_edge(v, u, i);
  }
  dfs1(1, 0);
  for (int i = 1; i <= n - 1; i++) {
    long long a = ci[i];
    long long b = n - ci[i];
    ci[i] = (a * (a - 1)) * b + (b * (b - 1)) * a;
  }
  double ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    ans += ci[i] * w[i];
  }
  int m;
  scanf("%d", &m);
  double sb = n * (long long)(n - 1) * (long long)(n - 2) / 6.0;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    ans -= (w[a] - b) * ci[a];
    printf("%lf\n", ans / sb);
    w[a] = b;
  }
  return 0;
}
