#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 3010
#define maxe 6010
#define cl(x) memset(x,0,sizeof(x))
#define rep(_,__) for(_=1;_<=(__);_++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
    ll c, f(1);
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
    for(;isdigit(c);c=getchar())x=x*10+c-0x30;
    return f*x;
}
struct Graph
{
    int etot, head[maxn], to[maxe], next[maxe], w[maxe];
    void clear(int N)
    {
        for(int i=1;i<=N;i++)head[i]=0;
        etot=0;
    }
    void adde(int a, int b, int c=0){to[++etot]=b;w[etot]=c;next[etot]=head[a];head[a]=etot;}
    #define forp(pos,G) for(auto p=G.head[pos];p;p=G.next[p])
}G;
ll f[maxn][maxn], n, m, a[maxn], b[maxn], w[maxn], g[maxn][maxn], sz[maxn];
void dfs(ll u, ll fa)
{
    ll i, j;
    sz[u]=1;
    f[u][1]=w[u]>0;
    g[u][1]=w[u];
    forp(u,G)if(G.to[p]!=fa)
    {
        auto v=G.to[p];
        dfs(v,u);
        ll ff[maxn], gg[maxn];
        rep(i,m)gg[i]=-linf, ff[i]=0;
        for(i=1;i<=sz[u];i++)for(j=1;j<=sz[v];j++)
        {
            if(f[u][i]+f[v][j]>ff[i+j])
            {
                ff[i+j]=f[u][i]+f[v][j];
                gg[i+j]=g[u][i];
            }
            else if(f[u][i]+f[v][j]==ff[i+j])
            {
                gg[i+j]=max(gg[i+j],g[u][i]);
            }
            ll t = f[u][i] + f[v][j] + - (g[u][i]>0) - (g[v][j]>0) + (g[u][i]+g[v][j]>0);
            if(t>ff[i+j-1])
            {
                ff[i+j-1]=t;
                gg[i+j-1]=g[u][i]+g[v][j];
            }
            else if(t==ff[i+j-1])
            {
                gg[i+j-1]=max(gg[i+j-1],g[u][i]+g[v][j]);
            }
        }
        rep(i,m)f[u][i]=ff[i], g[u][i]=gg[i];
        sz[u]+=sz[v];
    }
    rep(j,sz[u])
    {
        // printf("f[%lld][%lld]=%lld g=%lld\n",u,j,f[u][j],g[u][j]);
    }
}
int main()
{
    ll T=read(), u, v, i, j;
    while(T--)
    {
        G.clear(n);
        n=read(), m=read();
        rep(i,n)a[i]=read();
        rep(i,n)b[i]=read();
        rep(i,n)w[i]=b[i]-a[i];
        rep(i,n-1)u=read(), v=read(), G.adde(u,v), G.adde(v,u);
        rep(i,n)rep(j,m)f[i][j]=0, g[i][j]=-linf;
        dfs(1,0);
        printf("%lld\n",f[1][m]);
        // rep(i,n)rep(j,m)printf("f[%lld][%lld]=%lld\n",i,j,f[i][j]);
    }
    return 0;
}