#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int n;
int vs[100005];
vector<int> g[100005];
pair<int, int> e[100005];
double m[100005];
double tot;
long long int wt[100005];
int adj(int i, int a) {
  if (e[i].first == a) return e[i].second;
  return e[i].first;
}
long long int dfs(int u) {
  vs[u] = 1;
  long long int cnt = 1;
  for (int i = 0; i < (int)(g[u].size()); i++) {
    int k = g[u][i];
    int w = adj(k, u);
    if (!vs[w]) {
      long long int tp = dfs(w);
      long long int tp1 = n - tp;
      m[k] = 6;
      m[k] /= (double)n;
      m[k] *= (double)tp;
      m[k] /= (double)(n - 1);
      m[k] *= (double)tp1;
      assert(m[k] >= 0);
      cnt += tp;
    }
  }
  return cnt;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int a, b, c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    g[a].push_back(i);
    g[b].push_back(i);
    e[i] = make_pair(a, b);
    wt[i] = 1LL * c;
  }
  dfs(1);
  double sum = 0;
  for (int i = 0; i < n - 1; i++) {
    sum += wt[i] * m[i];
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    long long int k, l;
    scanf("%lld", &k);
    scanf("%lld", &l);
    k--;
    long long int dec = wt[k] - l;
    wt[k] = l;
    sum -= dec * m[k];
    printf("%.14lf\n", sum);
  }
  return 0;
}
