#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
int q;
int id[maxn];
int w[maxn];
int which[maxn];
int sz[maxn];
long long n;
bool vis[maxn];
int head[2 * maxn];
int etot;
struct Edge {
  int to, next, id;
} e[2 * maxn];
void addEdge(int u, int v, int id) {
  e[etot].to = v;
  e[etot].id = id;
  e[etot].next = head[u];
  head[u] = etot++;
  e[etot].to = u;
  e[etot].id = id;
  e[etot].next = head[v];
  head[v] = etot++;
}
void dfs(int u, int fa, int id) {
  vis[u] = 1;
  sz[u] = 1;
  which[id] = u;
  for (int i = head[u]; i != -1; i = e[i].next) {
    if (!vis[e[i].to] && e[i].to != fa) {
      dfs(e[i].to, u, e[i].id);
      sz[u] += sz[e[i].to];
    }
  }
}
int main() {
  memset(head, -1, sizeof(head));
  etot = 0;
  cin >> n;
  int u, v, x;
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d%d", &u, &v, &x);
    addEdge(u, v, i);
    w[i] = x;
  }
  dfs(1, -1, 0);
  scanf("%d", &q);
  long long all = n * (n - 1);
  long long cur = 0;
  long long l, r;
  for (int i = 1; i <= n - 1; i++) {
    u = which[i];
    l = sz[u];
    r = n - l;
    cur += w[i] * (l * r) * 6;
  }
  int idx;
  long long delta;
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &idx, &x);
    u = which[idx];
    delta = w[idx] - x;
    w[idx] = x;
    cur -= delta * sz[u] * (n - sz[u]) * 6;
    printf("%.10f\n", (double)cur / all);
  }
  return 0;
}
