#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define sz(w) ((int)(w).size())
#define all(w) (w).begin(), (w).end()
#define pb push_back
#define int long long
#define INF 1e18
#define dbg(x) cerr << #x << "->" << x << "\n";

const int N = 2e5 + 5;




 const int mod = 1e9+7;


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

    int ceiling(int a,int b){
      if(a%b!=0){
        return (a/b)+1;

      }
      else
        return (a/b);
    }

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





/*vector<pair<int, long long>> val;
    for (long long i = 2; i * i <= n; ++i) {
      int cnt = 0;
      while (n % i == 0) {
        ++cnt;
        n /= i;
      }
      if (cnt > 0) {
        val.push_back({cnt, i});
      }
    }
    if (n > 1) {
      val.push_back({1, n});
    }
  */




//int lp[MAX];
//int n, k, x;
//smallest prime factor

/*void preprocess() {
  for(int i = 2; i * i < MAX; i++)
    if(!lp[i])
      for(int j = i * i; j < MAX; j += i)
        if(!lp[j]) lp[j] = i;
  for(int i = 2; i < MAX; i++) {
    if(!lp[i]) lp[i] = i;
  }
  lp[1] = 1;
}*/
/*int fac[N], invfac[N];

int power(int a, int b, int m)
{
    int res = 1;
    a %= m;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

int modinv(int k)
{
    return power(k, mod-2, mod);
}

void precompute()
{
    fac[0] = fac[1] = 1;
    for(int i = 2; i < N; i++)
    {
        fac[i] = fac[i-1] * i;
        fac[i] %= mod;
    }
    invfac[N-1] = modinv(fac[N-1]);
    for(int i = N-2; i >= 0; i--)
    {
        invfac[i] = invfac[i+1] * (i+1);
        invfac[i] %= mod;
    }
}

int nCr(int n, int r)
{
    if(n<0 or r<0 or n<r)
        return 0;
    return (fac[n] * invfac[r] % mod) * invfac[n-r] % mod;
}*/
vector<int>adj[N];
int dp[N][2];
int rv[N];
int lv[N];

void dfs(int v,int par)
{
  dp[v][0] = 0;
  dp[v][1] = 0;
  for(auto u : adj[v])
  {
    if(u==par)
    {
      continue;
    }
    dfs(u,v);
    dp[v][0] += max(dp[u][0] + abs(lv[v]-lv[u]),dp[u][1] + abs(lv[v]-rv[u]));
    dp[v][1] += max(dp[u][1] + abs(rv[v]-rv[u]),dp[u][0] + abs(rv[v]-lv[u]));
  }

  return;
}




void solve()
{
  for(int i=1;i<=N;i++)
  {
    adj[i].clear();
  }
  for(int i=0;i<=N;i++)
  {
    for(int j=0;j<2;j++)
    {
      dp[i][j] = 0;
    }
  }
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>lv[i];
    cin>>rv[i];
  }

  for(int i=0;i<n-1;i++)
  {
    int x,y;
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }

  dfs(1,-1);
  int ans = max(dp[1][0],dp[1][1]);
  cout<<ans<<endl;





  return;
}

int32_t main()
{
  IOS;
  int tc;
  cin>>tc;


   while(tc--)
  {
    solve();
  }
  return 0;
}
