#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const double eps = 1e-9;
const double PI = acos(-1.0);
const int N = 105000;
struct gap {
  int u;
  int v;
  double w;
  int next;
} edge[N << 1];
int n, q;
int head[N];
int son[N], father[N];
double weight[N], times[N];
int k;
bool vis[N];
double base;
void push(int u, int v, double w) {
  edge[k].u = u;
  edge[k].next = head[u];
  edge[k].v = v;
  edge[k].w = w;
  head[u] = k++;
}
void dfs(int u, int f) {
  son[u] = 1;
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].v;
    if (v == f) continue;
    dfs(v, u);
    son[u] += son[v];
    father[v] = u;
  }
}
int main() {
  double sum = 0.0;
  memset(head, -1, sizeof head);
  memset(son, 0, sizeof son);
  memset(father, 0, sizeof father);
  scanf("%d", &n);
  base = (n * 1.0) * ((n - 1) * 1.0) / 2.0 * ((n - 2) * 1.0) / 3.0;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    double w;
    scanf("%d%d%lf", &u, &v, &w);
    push(u, v, w);
    push(v, u, w);
  }
  dfs(1, 0);
  for (int i = 1; i < n; i++) {
    int num = (i - 1) * 2;
    int u = edge[num].u, v = edge[num].v;
    weight[i] = edge[num].w;
    if (father[u] == v) swap(u, v);
    times[i] = (double)son[v] * (double)(n - son[v]);
    sum += times[i] * weight[i];
  }
  scanf("%d", &q);
  while (q--) {
    int num;
    double w, deta;
    scanf("%d%lf", &num, &w);
    deta = weight[num] - w;
    weight[num] = w;
    sum -= deta * times[num];
    printf("%.8lf\n", sum * ((n - 2) * 1.0) / base);
  }
  return 0;
}
