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

#define ll long long int
#define absdiff(a,b) (a>b)?a-b:b-a
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
const ll MOD = 1000000007;
// const ll ll_MAX = 1e15;
ll fast_expo(ll x,ll p){
  if(p==0) return 1;
  else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} 
  else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll invMod(ll num){
  return fast_expo(num, MOD - 2)%MOD;
}

const ll N = 1e5 + 5;
pair<ll, ll> arr[N];
ll dp[N][2];
vector<ll> AdjL[N];

void dfs(ll src, ll par){
  dp[src][0] = dp[src][1] = 0;
  ll val1 = 0, val2 = 0;
  for(auto i: AdjL[src]){
    if(i != par){
      dfs(i, src);
      val1 += max(dp[i][0] + abs(arr[i].ff - arr[src].ff), dp[i][1] + abs(arr[i].ss - arr[src].ff));
      val2 += max(dp[i][0] + abs(arr[i].ff - arr[src].ss), dp[i][1] + abs(arr[i].ss - arr[src].ss));
    }
  }
  dp[src][0] = val1;
  dp[src][1] = val2;
}

int main(){
  fast
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif

  ll t_c; t_c = 1;
  cin >> t_c;

  for(ll t_i = 0; t_i < t_c; ++t_i){
    ll n; cin >> n;
    for(ll i = 1; i <= n; ++i)
      cin >> arr[i].ff >> arr[i].ss;

    for(ll i = 1; i <= n; ++i)
      AdjL[i].clear();

    for(ll i = 1; i < n; ++i){
      ll x, y; cin >> x >> y;
      AdjL[x].pb(y);
      AdjL[y].pb(x);
    }  

    dfs(1, 1);
    cout << max(dp[1][0], dp[1][1]) << endl;
  }
  return 0;
}
