#include <bits/stdc++.h>
const int N = (int)1e5 + 123;
const long long inf = (long long)1e18 + 123;
using namespace std;
struct edge {
  int to, w, id;
  edge() {}
  edge(int to, int w, int id) : to(to), w(w), id(id) {}
};
int n, m;
int w[N];
int l, r, c;
vector<edge> g[N];
int sz[N];
long long p[N];
long long all;
double now;
void dfs(int v, int pr = -1) {
  sz[v]++;
  for (int i = 0; i < int((g[v]).size()); i++) {
    edge to = g[v][i];
    if (to.to == pr) continue;
    dfs(to.to, v);
    p[to.id] = 1ll * sz[to.to] * (n - sz[to.to]);
    all += 1ll * p[to.id] * to.w;
    sz[v] += sz[to.to];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &l, &r, &c);
    g[l].push_back(edge(r, c, i));
    g[r].push_back(edge(l, c, i));
    w[i] = c;
  }
  dfs(1);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &l, &r);
    all -= 1ll * p[l] * w[l];
    w[l] = r;
    all += 1ll * p[l] * w[l];
    now = all * 6.0 / n / (n - 1);
    printf("%.10f\n", now);
  }
  return 0;
}
