#include <bits/stdc++.h>
using namespace std;
const int maxn = 300500;
struct edge {
  int to, next;
  long long cc;
} P[maxn];
int head[maxn], si;
int fa[maxn];
long long num[maxn], V, nn;
void add_edge(int s, int t, long long c) {
  P[si].to = t;
  P[si].cc = c;
  P[si].next = head[s];
  head[s] = si++;
}
void dfs(int v, int f) {
  num[v] = 1;
  fa[v] = f;
  for (int i = head[v]; i != -1; i = P[i].next) {
    int u = P[i].to;
    if (u == f) continue;
    dfs(u, v);
    num[v] += num[u];
  }
}
double solve() {
  long long n1, n2;
  double sum;
  int u;
  sum = 0.0;
  dfs(1, -1);
  for (int i = 0; i < si; i += 2) {
    if (fa[P[i].to] == P[i ^ 1].to)
      u = P[i].to;
    else
      u = P[i ^ 1].to;
    n1 = num[1] - num[u];
    n2 = num[u];
    if (n1 >= 2) sum += (double)((n1 * (n1 - 1)) * n2 * P[i].cc) / nn;
    if (n2 >= 2) sum += (double)((n2 * (n2 - 1)) * n1 * P[i].cc) / nn;
  }
  return sum;
}
int main() {
  int s, T, u;
  long long n1, n2, c, t;
  double sum;
  memset(head, -1, sizeof(head));
  memset(num, 0, sizeof(num));
  memset(fa, -1, sizeof(fa));
  si = 0;
  scanf("%lld", &V);
  nn = (V * (V - 1) * (V - 2)) / 6;
  for (int i = 1; i < V; i++) {
    scanf("%d%d%lld", &s, &t, &c);
    add_edge(s, t, c);
    add_edge(t, s, c);
  }
  sum = solve();
  scanf("%d", &T);
  while (T--) {
    scanf("%d%lld", &s, &t);
    s = (s - 1) * 2;
    if (fa[P[s].to] == P[s ^ 1].to)
      u = P[s].to;
    else
      u = P[s ^ 1].to;
    n1 = num[1] - num[u];
    n2 = num[u];
    if (n1 >= 2) sum -= (double)((n1 * (n1 - 1)) * n2 * (P[s].cc - t)) / nn;
    if (n2 >= 2) sum -= (double)((n2 * (n2 - 1)) * n1 * (P[s].cc - t)) / nn;
    P[s].cc = t;
    P[s ^ 1].cc = t;
    printf("%f\n", sum);
  }
  return 0;
}
