#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
    ll sum;
    ll asum;
};
int a[3005];
vector<int>v[3005];
node dp[3005][3005];
node tmp[3005];
int dfs(int past,int now)
{
    int sz=1;
    dp[now][0].sum=0;
    dp[now][0].asum=a[now];
    for(auto u:v[now]){
        if(u==past)continue;
        int l=dfs(now,u);
        for(int i=0;i<l+sz;i++){
            tmp[i].sum=-1;
            tmp[i].asum=-1;
        }
        for(int i=0;i<=l;i++){
            for(int j=0;j<sz;j++){
                if(tmp[i+j].sum<dp[u][i].sum+dp[now][j].sum){
                    tmp[i+j].sum=dp[u][i].sum+dp[now][j].sum;
                    tmp[i+j].asum=dp[u][i].asum+dp[now][j].asum;
                }else if(tmp[i+j].sum==dp[u][i].sum+dp[now][j].sum&&tmp[i+j].asum<dp[u][i].asum+dp[now][j].asum){
                    tmp[i+j].sum=dp[u][i].sum+dp[now][j].sum;
                    tmp[i+j].asum=dp[u][i].asum+dp[now][j].asum;
                }
            }
        }
        for(int i=0;i<l+sz;i++){
            dp[now][i]=tmp[i];
        }
        sz+=l;
    }
    for(int i=sz-1;i>=0;i--){
        node x=dp[now][i];
        if(x.asum>0){
            x.sum++;
        }
        x.asum=0;
        if(dp[now][i+1].sum<x.sum||dp[now][i+1].sum==x.sum&&dp[now][i+1].asum<x.asum){
            dp[now][i+1]=x;
        }
    }
    return sz;
}
void work()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        v[i].clear();
    }
    for(int i=1;i<=n;i++){
        int k;
        scanf("%d",&k);
        a[i]=k-a[i];
    }
    for(int i=1;i<n;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j].sum=-1;
            dp[i][j].asum=-1;
        }
    }
    dfs(0,1);
    printf("%lld\n",dp[1][m].sum);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T;
    scanf("%d",&T);
    //cin>>T;
    //T=1;
    while(T--){
        work();
    }
}