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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Try2{
	
	
	
	static final int Mod = 100_000_0007;
	public static void main(String[] args) throws IOException {
		FastScanner fs = new FastScanner();
		int t= fs.nextInt();
		
		while(t-->0) {
			int n = fs.nextInt();
			Graph g = new Graph(n+1);
			
			long a[][] = new long[n][2];
			for(int i =0 ;i<n;i++) {
				a[i][0] = fs.nextLong();
				a[i][1] = fs.nextLong();
				
			}
			
			for(int i =0 ;i<n-1;i++) {
				int x=  fs.nextInt();
				int y = fs.nextInt();
				
				g.addEdge(x, y);
			}
			
			dp = new long[n+1][2];
			
			g.DFS(1, a);
			
			System.out.println(Math.max(dp[1][0], dp[1][1]));
		}
		
		
	}

	static long dp[][];
	static class Graph{
		boolean b=false;
		private int V; 
		private LinkedList<Integer> adj[];
	    
	    // Constructor
	    @SuppressWarnings("unchecked") Graph(int v)
	    {
	        V = v;
	        adj = new LinkedList[v];
	      
	        
	        for (int i = 0; i < v; ++i)
	            adj[i] = new LinkedList();
	    }
	    
	    // Function to add an edge into the graph
	    void addEdge(int v, int w)
	    {
	        adj[v].add(w); // Add w to v's list.
	        adj[w].add(v);
	        
	    }
	 
	    
	    // A function used by DFS
	    void DFSUtil(int v, boolean visited[], long[][] a)
	    {
	        // Mark the current node as visited and print it
	        visited[v] = true;
	        
//	        System.out.print(v + " ");
	 
	        // Recur for all the vertices adjacent to this
	        // vertex
	        Iterator<Integer> i = adj[v].listIterator();
	        while (i.hasNext())
	        {
	            int n = i.next();
	           
	            
	            if (!visited[n]) {
	            	DFSUtil(n, visited,a);
	            	
	            	dp[v][0] +=Math.max(Math.abs(a[v-1][0] - a[n-1][0]) + dp[n][0], Math.abs(a[v-1][0] - a[n-1][1]) + dp[n][1]);
	            	dp[v][1] +=Math.max(Math.abs(a[v-1][1] - a[n-1][0]) + dp[n][0], Math.abs(a[v-1][1] - a[n-1][1]) + dp[n][1]);
	            }
	                
	        }
	        
	        
	    }
	 
	    // The function to do DFS traversal.
	    // It uses recursive
	    // DFSUtil()
	    void DFS(int v, long[][] a)
	    {
	        // Mark all the vertices as
	        // not visited(set as
	        // false by default in java)
	        boolean visited[] = new boolean[V];
	        
	      
	        DFSUtil(v, visited,a);
	        
	    }
	 
	}
	static final Random random = new Random();

	static void ruffleSort(int[] a) {
		int n = a.length;// shuffle, then sort
		for (int i = 0; i < n; i++) {
			int oi = random.nextInt(n), temp = a[oi];
			a[oi] = a[i];
			a[i] = temp;
		}
		Arrays.sort(a);
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

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

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

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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

}
