#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 9;
const long long oo = 1e15;
const long long mod = 1e9 + 7;
struct book {
  long long u, v, val;
} eg[N];
long long n, m, sum = 0ll;
long long pr[N], child[N];
vector<vector<pair<long long, long long> > > vi;
void dfs(long long pre, long long u) {
  pr[u] = pre;
  child[u] = 1;
  for (long long i = 0; i < vi[u].size(); ++i) {
    long long v = vi[u][i].first;
    if (v != pre) {
      dfs(u, v);
      child[u] += child[v];
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vi.resize(N);
  for (long long i = 1; i <= n - 1; ++i) {
    cin >> eg[i].u >> eg[i].v >> eg[i].val;
    long long x = eg[i].u, y = eg[i].v, z = eg[i].val;
    vi[x].push_back(make_pair(y, z));
    vi[y].push_back(make_pair(x, z));
  }
  dfs(1, 1);
  for (long long i = 1; i <= n - 1; ++i) {
    long long u = eg[i].u, v = eg[i].v, val = eg[i].val;
    if (pr[u] == v) swap(u, v);
    sum += 1ll * child[v] * (n - child[v]) * val;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long x;
    cin >> x;
    long long u = eg[x].u, v = eg[x].v, val = eg[x].val;
    if (pr[u] == v) swap(u, v);
    long long nx;
    cin >> nx;
    eg[x].val = nx;
    val;
    sum -= 1ll * child[v] * (n - child[v]) * (val - nx);
    long double tmp = (long double)(sum * 6.00) / (n * (n - 1) * 1ll);
    cout << fixed << setprecision(10) << tmp << '\n';
  }
}
