#include <bits/stdc++.h>
using namespace std;
struct node {
  int u, v, next;
  double w;
} edge[100009 * 2];
int head[100009], n, m, tot;
int L[100009], num[100009];
void addedge(int u, int v, double w) {
  edge[tot].u = u;
  edge[tot].v = v;
  edge[tot].w = w;
  edge[tot].next = head[u];
  head[u] = tot++;
}
void dfs1(int u, int fa, int dep) {
  L[u] = dep;
  num[u] = 1;
  for (int e = head[u]; e != -1; e = edge[e].next) {
    int v = edge[e].v;
    if (v == fa) continue;
    dfs1(v, u, dep + 1);
    num[u] += num[v];
  }
}
int main() {
  cin >> n;
  memset(head, -1, sizeof(head));
  tot = 0;
  for (int i = 0; i < n - 1; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    addedge(x, y, z);
    addedge(y, x, z);
  }
  dfs1(1, -1, 0);
  double sum = 0, cnt = (double)n * (n - 1) * (n - 2) / 6;
  for (int i = 0; i < tot; i += 2) {
    int u = edge[i].u;
    int v = edge[i].v;
    if (L[u] > L[v]) swap(u, v);
    double num1 = num[v], num2 = n - num[v];
    sum = sum + num1 * num2 * (num2 - 1) * edge[i].w;
    sum = sum + num2 * num1 * (num1 - 1) * edge[i].w;
  }
  int Q, id, nw;
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &id, &nw);
    id--;
    double val = edge[2 * id].w - nw;
    int u = edge[2 * id].u;
    int v = edge[2 * id].v;
    if (L[u] > L[v]) swap(u, v);
    edge[2 * id].w = nw;
    edge[(2 * id) ^ 1].w = nw;
    double num1 = num[v], num2 = n - num[v];
    sum = sum - num1 * num2 * (num2 - 1) * val;
    sum = sum - num2 * num1 * (num1 - 1) * val;
    printf("%.12f\n", sum / cnt);
  }
  return 0;
}
