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.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class CF722D2C {
	public static void main(String[] args) throws IOException {
		int T = readInt();
		for (int t = 0; t < T; t++) {
			int N = readInt();
			int M = N - 1;
			
			List<Integer>[] graph = new List[N+1];
			for (int i = 1; i <= N; i++) {
				graph[i] = new ArrayList<>();
			}
			Pair[] nodes = new Pair[N+1];
			for (int i = 1; i <= N; i++) {
				nodes[i] = new Pair(readInt(), readInt());
			}
			
			for (int i = 0; i < M; i++) {
				int a = readInt();
				int b = readInt();
				graph[a].add(b);
				graph[b].add(a);
			}
			
			long[][] dp = new long[N+1][2];
			dfs(graph, nodes, 1, 0, dp, true);
			dfs(graph, nodes, 1, 0, dp, false);
			long ans = Math.max(dp[1][0], dp[1][1]);
			println(ans);
		}
	}
	
	static void dfs(List<Integer>[] graph, Pair[] nodes, int cur, int pre, long[][] dp, boolean l) {
		int c = 1;
		if (l) {
			c = 0;
		}
		for (int b : graph[cur]) {
			if (b != pre) {
				if (dp[b][c] == 0) {
					dfs(graph, nodes, b, cur, dp, true);
					dfs(graph, nodes, b, cur, dp, false);
				}
				if (l) {
					long v1 = Math.abs(nodes[cur].a - nodes[b].a);
					long v2 = Math.abs(nodes[cur].a - nodes[b].b);
					dp[cur][0] += Math.max(dp[b][0] + v1, dp[b][1] + v2);
				} else {
					long v1 = Math.abs(nodes[cur].b - nodes[b].a);
					long v2 = Math.abs(nodes[cur].b - nodes[b].b);
					dp[cur][1] += Math.max(dp[b][0] + v1, dp[b][1] + v2);
				}
			}
		}
	}
	
	private static class Pair {
		int a;
		int b;
		public Pair(int a, int b) {
			this.a=a;
			this.b=b;
		}
		public String toString() {
			return "(" + a + "," + b + ")";
		}
	}

	static int[] arr(int N) throws IOException {
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = readInt();
		}
		return a;
	}
	
	static void print(Object x) {
		System.out.print(x);
	}
	static void println(Object x) {
		System.out.println(x);
	}
	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	
	public static char readChar() throws IOException {
		byte c = Read();
		while (c <= ' ')
			c = Read();
		return (char) c;
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}
	
	public static String readString() throws IOException{
		byte[] ret = new byte[10001];
        int idx = 0;
        byte c = Read();
        while (c <= ' ') {
            c = Read();
        }
        do {
            ret[idx++] = c;
            c = Read();
        } while (c != -1 && c != ' ' && c != '\n' && c != '\r');
        return new String(ret, 0, idx);
	}
	
	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}
	
	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}
}
