#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u;
  int v;
  long long cost;
  edge() {}
  edge(int u, int v, long long c) : u(u), v(v), cost(c) {}
};
long long comb2(long long n) { return (n * (n - 1)) / 2; }
const int MAXN = 100100;
int n;
vector<int> G[MAXN];
edge es[MAXN];
int childNum[MAXN];
long long usedNum[MAXN];
int dfs(int v, int par) {
  if (childNum[v] >= 0) return childNum[v];
  int ret = 1;
  for (int i = 0; i < (int)G[v].size(); i++) {
    int next = G[v][i];
    if (next != par) ret += dfs(next, v);
  }
  return childNum[v] = ret;
}
int main(void) {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> es[i].u >> es[i].v >> es[i].cost;
    G[es[i].u].push_back(es[i].v);
    G[es[i].v].push_back(es[i].u);
  }
  for (int i = 1; i <= n; i++) childNum[i] = -1;
  dfs(1, 0);
  double sum = 0;
  for (int i = 0; i < n - 1; i++) {
    int x = min(childNum[es[i].u], childNum[es[i].v]);
    usedNum[i] = 2 * (x * comb2(n - x) + (n - x) * comb2(x));
    sum += (double)usedNum[i] * (double)es[i].cost;
  }
  int q;
  long long div = (long long)n * (long long)(n - 1) * (long long)(n - 2) / 6;
  cin >> q;
  while (q--) {
    int id;
    long long cost;
    cin >> id >> cost;
    id--;
    long long diff = es[id].cost - cost;
    es[id].cost = cost;
    sum -= (double)diff * (double)usedNum[id];
    printf("%.10lf\n", sum / (double)div);
  }
  return 0;
}
