

#include <bits/stdc++.h>
using namespace std;
using namespace std;
#include<iostream> 
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
int xc[N];
int yc[N];
int pow(int a, int b, int m)
{
    int ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % m;
        b /= 2;
        a = (a * a) % m;
    }
    return ans;
}

int n, k, sz, ans = 0;
bool vis[N];
vector<int> g[N];
vector<int> ansx[N];
vector<int> ansy[N];
void dfs(int a, int b)
{
   

    for (int i = 0; i < g[a].size(); i++)
    {
        if (g[a][i] != b)
        {
            dfs(g[a][i], a);
            ansx[a][0]+=max(ansx[g[a][i]][0]+abs(xc[a]-xc[g[a][i]]),ansy[g[a][i]][0]+abs(xc[a]-yc[g[a][i]]));
            ansy[a][0]+=max(ansx[g[a][i]][0]+abs(yc[a]-xc[g[a][i]]),ansy[g[a][i]][0]+abs(yc[a]-yc[g[a][i]]));
        }
    }
    
}

int32_t main()
{
    IOS;
    int ts;
    cin >> ts;
    while (ts--)
    {
        cin >> n;
        for(int i=1;i<=n+1;i++){
            ansx[i].clear();
            ansy[i].clear();
            g[i].clear();
        }
        for (int i = 1; i <= n; i++)
        {
            int a, b;
            cin >> a >> b;
            xc[i] = a;
            yc[i] = b;
        }
        for (int i = 1; i <= n - 1; i++)
        {
            int u, v;
            cin >> u >> v;

            g[u].push_back(v), g[v].push_back(u);
            ansx[u].push_back(0);
            ansx[v].push_back(0);
            ansy[u].push_back(0);
            ansy[v].push_back(0);
        }

        dfs(1,-1);

        cout <<max(ansx[1][0],ansy[1][0])<<endl;
    }
    return 0;
}