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.*;
 
public class Main {
 
  static class Task {
 
    int NN = 200005;
    int MOD = 1000000007;
    int INF = 2000000000;
    long INFINITY = 2000000000000000000L;

	int [] a;
	int [] b;
	List<Integer> [] g;
	long [][] dp;

	long rec(int node, int prev, int index) {
		if(dp[node][index] != -1){
			return dp[node][index];
		}
		long ret = 0;
		int val = index==0?a[node]:b[node];
		for(int adj: g[node]) {
			if(adj == prev) {
				continue;
			}
			ret += Math.max((long)(rec(adj, node, 0) + (long)(Math.abs(val - a[adj]))), (long)(rec(adj, node, 1) + (long)(Math.abs(val - b[adj]))));
		}
		return dp[node][index] = ret;
	}
    
    public void solve(InputReader in, PrintWriter out) {
		int t = in.nextInt();
		while(t-->0) {
			int n = in.nextInt();
			a = new int[n + 1];
			b = new int[n + 1];
			g = new ArrayList[n + 1];
			dp = new long[n + 1][2];
			for(int i=1;i<=n;++i) {
				a[i] = in.nextInt();
				b[i] = in.nextInt();
				g[i] = new ArrayList<>();
				dp[i][0] = dp[i][1] = -1;
			}
			for(int i=1;i<n;++i) {
				int u = in.nextInt();
				int v = in.nextInt();
				g[u].add(v);
				g[v].add(u);
			}
			long ans = Math.max(rec(1, -1, 0), rec(1, -1, 1));
			out.println(ans);
		}
    }
  }
 
  static void prepareIO(boolean isFileIO) {
    // long t1 = System.currentTimeMillis();
    Task solver = new Task();
    // Standard IO
    if (!isFileIO) {
      InputStream inputStream = System.in;
      OutputStream outputStream = System.out;
      InputReader in = new InputReader(inputStream);
      PrintWriter out = new PrintWriter(outputStream);
      solver.solve(in, out);
      // out.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
      out.close();
    }
    // File IO
    else {
      String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
      String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
      InputReader fin = new InputReader(IPfilePath);
      PrintWriter fout = null;
      try {
        fout = new PrintWriter(new File(OPfilePath));
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
      solver.solve(fin, fout);
      // fout.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
      fout.close();
    }
  }
 
  public static void main(String[] args) {
    prepareIO(false);
  }
 
  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
 
    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }
 
    public InputReader(String filePath) {
      File file = new File(filePath);
      try {
        reader = new BufferedReader(new FileReader(file));
      } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      tokenizer = null;
    }
 
    public String nextLine() {
      String str = "";
      try {
        str = reader.readLine();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      return str;
    }
 
    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }
 
    public int nextInt() {
      return Integer.parseInt(next());
    }
 
    public long nextLong() {
      return Long.parseLong(next());
    }
 
    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }
}