Parsa has a humongous tree on n vertices.

On each vertex v he has written two integers l_v and r_v.

To make Parsa's tree look even more majestic, Nima wants to assign a number a_v (l_v ≤ a_v ≤ r_v) to each vertex v such that the beauty of Parsa's tree is maximized.

Nima's sense of the beauty is rather bizarre. He defines the beauty of the tree as the sum of |a_u - a_v| over all edges (u, v) of the tree.

Since Parsa's tree is too large, Nima can't maximize its beauty on his own. Your task is to find the maximum possible beauty for Parsa's tree.

Input

The first line contains an integer t (1≤ t≤ 250) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (2≤ n≤ 10^5) — the number of vertices in Parsa's tree.

The i-th of the following n lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^9).

Each of the next n-1 lines contains two integers u and v (1 ≤ u , v ≤ n, u≠ v) meaning that there is an edge between the vertices u and v in Parsa's tree.

It is guaranteed that the given graph is a tree.

It is guaranteed that the sum of n over all test cases doesn't exceed 2 ⋅ 10^5.

Output

For each test case print the maximum possible beauty for Parsa's tree.

Example

Input


3
2
1 6
3 8
1 2
3
1 3
4 6
7 9
1 2
2 3
6
3 14
12 20
12 19
2 12
10 17
3 17
3 2
6 5
1 5
2 6
4 6


Output


7
8
62

Note

The trees in the example:

<image>

In the first test case, one possible assignment is a = \{1, 8\} which results in |1 - 8| = 7.

In the second test case, one of the possible assignments is a = \{1, 5, 9\} which results in a beauty of |1 - 5| + |5 - 9| = 8
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;

import static java.lang.Double.parseDouble;
import static java.lang.Integer.compare;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.in;
import static java.lang.System.out;
import static java.util.Arrays.asList;
import static java.util.Collections.max;
import static java.util.Collections.min;

public class Main {
    private static final int MOD = (int) (1E9 + 7);
    private static final int INF = (int) (1E9);
    static long ans = 0;
    static FastScanner scanner = new FastScanner(in);

    public static void main(String[] args) throws IOException {
        // Write your solution here
        StringBuilder answer = new StringBuilder();
        int t = 1;
        t = parseInt(scanner.nextLine());
        while (t-- > 0) {
            answer.append(solve()).append("\n");
        }
        out.println(answer);
    }

    private static Object solve() throws IOException {
        int n = scanner.nextInt();
        Pair[] p = new Pair[n + 1];
        for (int i = 1; i <= n; i++) {
            p[i] = new Pair(scanner.nextInt(), scanner.nextInt());
        }
        HashMap<Integer, List<Integer>> tree = new HashMap<>();
        for (int i = 1; i < n + 1; i++) {
            tree.put(i, new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int u = scanner.nextInt();
            int v = scanner.nextInt();
            tree.get(u).add(v);
            tree.get(v).add(u);
        }
        ans = 0;
        long[][] dp = new long[n + 1][2]; //


        long ans = maxx(
                dfs(tree, p, dp, 1, -1, 1),
                dfs(tree, p, dp, 1, -1, 0)
        );
        return ans;
    }

    private static long dfs(HashMap<Integer, List<Integer>> tree, Pair[] p, long[][] dp, int node, int parent, int w) {
        long ans = 0;
        if (dp[node][w] != 0) return dp[node][w];
        int a = (w == 0) ? p[node].l : p[node].r;
        for (int v : tree.get(node)) {
            if (v == parent) continue;
            long al = dfs(tree, p, dp, v, node, 0);
            long ar = dfs(tree, p, dp, v, node, 1);
            ans += Math.max(
                    al + Math.abs(p[v].l - a),
                    ar + Math.abs(p[v].r - a)
                );
        }
        return dp[node][w] = ans;
//        if (l == 0 && r == 0) {
//            if (Math.abs(p[parent].l - p[node].r) > Math.abs(p[parent].r - p[node].l)) {
//                out.println("node = " + node + " a = " + p[node].r);
//                return p[node].r;
//            }
//            out.println("node = " + node + " a = " + p[node].l);
//            return p[node].l;
//        }
//        if (l > r) {
//            ans += l;
//            out.println("node = " + node + " a = " + p[node].l);
//            return p[node].l;
//        }
//        ans += r;
//        out.println("node = " + node + " a = " + p[node].r);
//        return p[node].r;
    }

    private static int maxx(Integer... a) {
        return max(asList(a));
    }

    private static int minn(Integer... a) {
        return min(asList(a));
    }

    private static long maxx(Long... a) {
        return max(asList(a));
    }

    private static long minn(Long... a) {
        return min(asList(a));
    }

    private static int add(int a, int b) {
        long res = ((long) (a + MOD) % MOD + (b + MOD) % MOD) % MOD;
        return (int) res;
    }

    private static int mul(int a, int b) {
        long res = ((long) a % MOD * b % MOD) % MOD;
        return (int) res;
    }

    private static int pow(int a, int b) {
        a %= MOD;
        int res = 1;
        while (b > 0) {
            if ((b & 1) != 0)
                res = mul(res, a);
            a = mul(a, a);
            b >>= 1;
        }
        return res;
    }

    private static int gcd(int a, int b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    private static int lcm(int a, int b) {
        return (a / gcd(a, b)) * b;
    }

    private static class Pair implements Comparable<Pair> {
        int l, r;

        public Pair(int index, int value) {
            this.l = index;
            this.r = value;
        }

        public int compareTo(Pair o) {
            if (r != o.r) return compare(r, o.r);
            return compare(l, o.l);
        }
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return parseInt(next());
        }

        long nextLong() {
            return parseLong(next());
        }

        double nextDouble() {
            return parseDouble(next());
        }

    }
}