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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }

template<class T> void DBG(T&& x) { cerr << x << " "; }
template<class T, class...Args> void DBG(T&& x, Args&&... args) { DBG(x); DBG(args...); }
#define DBG(...) { cerr << "[" << #__VA_ARGS__ << "]: "; DBG(__VA_ARGS__); cerr << endl; }
template<class num> inline void rd(num& x) { cin >> x; }
template <class Ty, class... Args> inline void rd(Ty& x, Args&... args) { rd(x); rd(args...); }
template<class num> inline void print(num&& x) { cout << x; }
template <class Ty, class... Args> inline void print(Ty&& x, Args&&... args) { print(x); print(' '); print(args...); }
#define print(...) print(__VA_ARGS__), print('\n')

const int MAXN = 1e5 + 5;

ll pos[MAXN][2];
vector<vector<int>> edges;
vector<vector<ll>> memo;

ll dfs(int u, int p, int cur) {
	ll& ans = memo[u][cur];
	if (~ans) return ans;

	for (int i = 0; i < 2; i++) {
		ll cur_ans = 0;
		if (u != 1) cur_ans += abs(pos[u][i] - pos[p][cur]);
		for (int v : edges[u]) if (v != p) {
			cur_ans += dfs(v, u, i);
		}
		ans = max(ans, cur_ans);
	}

	return ans;
}

inline void run_test(int test_number) {
	int n; rd(n);
	for (int i = 1; i <= n; i++) rd(pos[i][0], pos[i][1]);
	edges.clear();
	edges.resize(n + 1);
	for (int i = 1; i < n; i++) {
		int u, v; rd(u, v);
		edges[u].pb(v);
		edges[v].pb(u);
	}
	memo = vector<vector<ll>>(n + 1, vector<ll>(2, -1));
	print(dfs(1, 1, 0));
}

int main() {

//#ifndef LOCAL_PC
//	freopen("FILE.in", "r", stdin);
//#endif

	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n_tests = 1;
	rd(n_tests);
	for (int i = 1; i <= n_tests; i++) run_test(i);
}