Problem: New Year is coming in Tree World! In this world, as the name implies, there are n cities connected by n - 1 roads, and for any two distinct cities there always exists a path between them. The cities are numbered by integers from 1 to n, and the roads are numbered by integers from 1 to n - 1. Let's define d(u, v) as total length of roads on the path between city u and city v.

As an annual event, people in Tree World repairs exactly one road per year. As a result, the length of one road decreases. It is already known that in the i-th year, the length of the ri-th road is going to become wi, which is shorter than its length before. Assume that the current year is year 1.

Three Santas are planning to give presents annually to all the children in Tree World. In order to do that, they need some preparation, so they are going to choose three distinct cities c1, c2, c3 and make exactly one warehouse in each city. The k-th (1 ≤ k ≤ 3) Santa will take charge of the warehouse in city ck.

It is really boring for the three Santas to keep a warehouse alone. So, they decided to build an only-for-Santa network! The cost needed to build this network equals to d(c1, c2) + d(c2, c3) + d(c3, c1) dollars. Santas are too busy to find the best place, so they decided to choose c1, c2, c3 randomly uniformly over all triples of distinct numbers from 1 to n. Santas would like to know the expected value of the cost needed to build the network.

However, as mentioned, each year, the length of exactly one road decreases. So, the Santas want to calculate the expected after each length change. Help them to calculate the value.

Input

The first line contains an integer n (3 ≤ n ≤ 105) — the number of cities in Tree World.

Next n - 1 lines describe the roads. The i-th line of them (1 ≤ i ≤ n - 1) contains three space-separated integers ai, bi, li (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ li ≤ 103), denoting that the i-th road connects cities ai and bi, and the length of i-th road is li.

The next line contains an integer q (1 ≤ q ≤ 105) — the number of road length changes.

Next q lines describe the length changes. The j-th line of them (1 ≤ j ≤ q) contains two space-separated integers rj, wj (1 ≤ rj ≤ n - 1, 1 ≤ wj ≤ 103). It means that in the j-th repair, the length of the rj-th road becomes wj. It is guaranteed that wj is smaller than the current length of the rj-th road. The same road can be repaired several times.

Output

Output q numbers. For each given change, print a line containing the expected cost needed to build the network in Tree World. The answer will be considered correct if its absolute and relative error doesn't exceed 10 - 6.

Examples

Input

3
2 3 5
1 3 3
5
1 4
2 2
1 2
2 1
1 1


Output

14.0000000000
12.0000000000
8.0000000000
6.0000000000
4.0000000000


Input

6
1 5 3
5 3 2
6 1 7
1 4 4
5 2 3
5
1 2
2 1
3 5
4 1
5 2


Output

19.6000000000
18.6000000000
16.6000000000
13.6000000000
12.6000000000

Note

Consider the first sample. There are 6 triples: (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1). Because n = 3, the cost needed to build the network is always d(1, 2) + d(2, 3) + d(3, 1) for all the triples. So, the expected cost equals to d(1, 2) + d(2, 3) + d(3, 1).

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class ProblemD3 {
    BufferedReader rd;
    List<Map<Integer, Integer>> edges = new ArrayList<>();
    int[][] roads;
    Map<Integer, Map<Integer, double[]>> s;

    private ProblemD3() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        int n = pint();
        for(int i=0;i<n;i++) {
            edges.add(new HashMap<Integer, Integer>());
        }
        roads = new int[n-1][];
        for(int i=0;i<n-1;i++) {
            int[] a = intarr();
            addEdge(a[0]-1,a[1]-1,a[2]);
            roads[i] = a;
        }
        Set<Integer> singles = new HashSet<>();
        for(int i=0;i<n;i++) {
            if(neighbourCount(i) == 1) {
                singles.add(i);
            }
        }
        Set<Integer> processed = new HashSet<>();
        s = new HashMap<>();
        Queue<Integer> completed = new LinkedList<>();
        completed.addAll(singles);
        processed.addAll(singles);
        int root = -1;
        while(!completed.isEmpty()) {
            Integer node = completed.poll();
            if(singles.contains(node)) {
                Map.Entry<Integer, Integer> onlyRoad = edges.get(node).entrySet().iterator().next();
                int neighbour = onlyRoad.getKey();
                double length = onlyRoad.getValue();
                Map<Integer, double[]> v = s.get(neighbour);
                if(v == null) {
                    v = new HashMap<>();
                    s.put(neighbour, v);
                }
                v.put(node, new double[] { 1, length });
                if(v.size() >= neighbourCount(neighbour)-1) {
                    if(processed.add(neighbour)) {
                        completed.add(neighbour);
                    }
                }
            } else {
                Map<Integer, double[]> v = s.get(node);
                int vs = v.size();
                if(vs == neighbourCount(node)) {
                    root = node;
                } else {
                    int next = -1;
                    double length = -1;
                    for(Map.Entry<Integer, Integer> e: edges.get(node).entrySet()) {
                        int neighbour = e.getKey();
                        if(v.get(neighbour) == null) {
                            next = neighbour;
                            length = e.getValue();
                            break;
                        }
                    }
                    Map<Integer, double[]> vnext = s.get(next);
                    if(vnext == null) {
                        vnext = new HashMap<>();
                        s.put(next, vnext);
                    }
                    double[] st = new double[] { 1, length };
                    for(Map.Entry<Integer, double[]> e2: v.entrySet()) {
                        double[] naw = e2.getValue();
                        st[0] += naw[0];
                        st[1] += naw[0]*length + naw[1];
                    }
                    vnext.put(node, st);
                    if(vnext.size() == neighbourCount(next)-1) {
                        if(processed.add(next)) {
                            completed.add(next);
                        }
                    } else if(vnext.size() == neighbourCount(next)) {
                        root = next;
                        completed = new LinkedList<>();
                    }
                }
            }
        }

        processed = new HashSet<>();
        completed.add(root);
        processed.add(root);
        while(!completed.isEmpty()) {
            Integer polled = completed.poll();
            Map<Integer, double[]> v = s.get(polled);
            if(v == null) {
                v = new HashMap<>();
                s.put(polled, v);
            }

            double s2 = 1;
            double s5 = 0;
            for(Map.Entry<Integer, double[]> e2: v.entrySet()) {
                s2 += e2.getValue()[0];
                s5 += e2.getValue()[1];
            }

            for(Map.Entry<Integer, Integer> e3: edges.get(polled).entrySet()) {
                int node = e3.getKey();
                if(processed.add(node)) {
                    Map<Integer, double[]> vnext = s.get(node);
                    if(vnext == null) {
                        vnext = new HashMap<>();
                        s.put(node, vnext);
                    }
                    double s3 = s2;
                    double s6 = s5;
                    double[] e4 = v.get(node);
                    if(e4 != null) {
                        s3 -= e4[0];
                        s6 -= e4[1];
                    }
                    int length = e3.getValue();
                    double[] st = new double[] { s3, length*s3 + s6 };
                    vnext.put(polled, st);
                    completed.add(node);
                }

            }
        }

        double s1 = computeS1();
        double sum = computeSum();
        int q = pint();
        for(int i=0;i<q;i++) {
            int[] a = intarr();
            int r = a[0];
            int w = a[1];
            long diff = roads[r-1][2]-w;
            roads[r-1][2] = w;
            double[] p = new double[2];
            for(int x=0;x<2;x++) {
                int from = roads[r-1][x]-1;
                int to = roads[r-1][1-x]-1;
                Map<Integer, double[]> v = s.get(from);
                if(v != null) {
                    p[x] = v.get(to)[0];
                }
            }
            double t = 0;
            for(int x=0;x<2;x++) {
                if(p[x] > 1) {
                    t += comb2(p[x])*p[1-x];
                }
            }
            s1 -= diff*t;
            out((s1*2D)/sum);
        }
    }

    private double comb2(double a) {
        return a*(a-1)/2;
    }

    private double computeSum() {
        double sum = 0;
        for(Map.Entry<Integer, Map<Integer, double[]>> e: s.entrySet()) {
            if(e.getValue().size() >= 2) {
                double[] a = new double[e.getValue().size()];
                int ix = 0;
                for(Map.Entry<Integer, double[]> e2: e.getValue().entrySet()) {
                    a[ix++] = e2.getValue()[0];
                }
                double kw = 0;
                double p = 0;
                for(double x: a) {
                    kw += x*x;
                    p += x;
                }
                sum += (p*p-kw)/2;
                double sa = 0;
                for(int i=0;i<ix;i++) {
                    sa += a[i];
                }
                double ssa = 0;
                for(int i=0;i<ix;i++) {
                    ssa += a[i] * (sa - a[i]);
                }
                double sssa = 0;
                for(int i=0;i<ix;i++) {
                    sssa += a[i]*(ssa/2 - a[i]*(sa-a[i]));
                }
                sum += sssa/3;
            }
        }
        return sum;
    }

    private double computeS1() {
        double s1 = 0;
        for(Map.Entry<Integer, Map<Integer, double[]>> e2: s.entrySet()) {
            Map<Integer, double[]> v = e2.getValue();
            if(e2.getValue().size() >= 2) {
                double as = 0;
                double bs = 0;
                for(Map.Entry<Integer, double[]> e: v.entrySet()) {
                    as += e.getValue()[0];
                    bs += e.getValue()[1];
                }
                double all = 0;
                for(Map.Entry<Integer, double[]> e: v.entrySet()) {
                    all += e.getValue()[0]*(as-e.getValue()[0]);
                    double add = e.getValue()[0]*(bs-e.getValue()[1]);
                    s1 += add;
                }

                for(Map.Entry<Integer, double[]> e: v.entrySet()) {
                    double k = e.getValue()[0];
                    double add = e.getValue()[1]*(all/2-(as-k)*k);
                    s1 += add;
                }
            }
        }

        return s1;
    }

    private int neighbourCount(int node) {
        return edges.get(node).size();
    }

    private void addEdge(int from, int to, int len) {
        edges.get(from).put(to, len);
        edges.get(to).put(from, len);
    }


    private int pint() throws IOException {
        return pint(rd.readLine());
    }

    private int pint(String s) {
        return Integer.parseInt(s);
    }



    private int[] intarr() throws IOException {
        return intarr(rd.readLine());
    }

    private int[] intarr(String s) {
        String[] q = split(s);
        int n = q.length;
        int[] a = new int[n];
        for(int i=0;i<n;i++) {
            a[i] = Integer.parseInt(q[i]);
        }
        return a;
    }

    private String[] split(String s) {
        int n = s.length();
        int sp = 0;
        for(int i=0;i<n;i++) {
            if(s.charAt(i)==' ') {
                sp++;
            }
        }
        String[] res = new String[sp+1];
        int last = 0;
        int x = 0;
        for(int i=0;i<n;i++) {
            char c = s.charAt(i);
            if(c == ' ') {
                res[x++] = s.substring(last,i);
                last = i+1;
            }
        }
        res[x] = s.substring(last,n);
        return res;
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new ProblemD3();
    }
}