func_code_string: #include<bits/stdc++.h>   #define fre(x) freopen(#x .in , r ,stdin);freopen(#x .out , w ,stdout)   #define ll long long   using namespace std;   inline int read(){    int x=0,f=1;char c=getchar();    while(c< 0 ||c> 9 ) { if(c== - ) f=-1;c=getchar(); }    while(c>= 0 &&c<= 9 ) x=(x<<3)+(x<<1)+(c^ 0 ),c=getchar();    return x*f;   }   const int N=1e5+5;   int n,l[N],r[N];   ll f[N][2];   vector<int>e[N];   void dfs(int x,int fa){    f[x][0]=f[x][1]=0;    for(auto y:e[x]) if(y^fa){     dfs(y,x);     f[x][0]+=max(f[y][0]+abs(l[x]-l[y]),f[y][1]+abs(l[x]-r[y]));     f[x][1]+=max(f[y][0]+abs(r[x]-l[y]),f[y][1]+abs(r[x]-r[y]));    }   }   inline void solve(){    n=read();    for(int i=1;i<=n;i++) l[i]=read(),r[i]=read(),e[i].clear();    for(int i=1;i<n;i++){     int x=read(),y=read();     e[x].push_back(y);     e[y].push_back(x);    }    dfs(1,0);    printf( %lld n ,max(f[1][0],f[1][1]));   }   int main(){    int T=read();    while(T--) solve();    return 0;   }