//#pragma GCC optimize(3)

#include<bits/stdc++.h>
#define MST(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i = a ; i < b ; ++i)
#define per(i,a,b) for(int i = a ; i > b ; --i)
#define ALL(v) v.begin(),v.end()
#define ft first
#define sd second
using namespace std;

template<class T> void show(T *x,int len,int s = 0) {for(int i = s ; i < s+len-1 ; ++i) cerr << x[i] << ' ';cerr << x[s+len-1] << endl;}
void debug() {cerr << endl;}
template <typename T, typename... Args> void debug(T x,Args... args) {cerr << x << ' ';debug(args...);}
typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int,int> pii;
#include <ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
typedef __gnu_pbds::priority_queue<pii,greater<pii>,pairing_heap_tag> heap;
typedef heap::point_iterator iter;
template<class T>
inline void cmin(T &A,const T &B) {A = (A<B?A:B);}
template<class T>
inline void cmax(T &A,const T &B) {A = (A>B?A:B);}

const int N = 3000+19;
typedef pair<LL,LL> pll;
pll f[N][N];
vector<int> e[N];
int n,M,sz[N],b[N],w[N];

void update(pll &A,pll x,pll y) {
    x.first += y.first;
    x.second += y.second;
    if(A.first < x.first || (A.first == x.first && A.second > x.second))
        A = x;
}

void merge(pll *f,int &n,pll *g, int &m) {
    static pll temp[N];
    for(int i = 0 ; i < n+m && i < M; ++i) temp[i] = pll(-1,0);
    for(int i = 0 ; i < n && i < M ; ++i)
        for(int j = 0 ; j < m && i+j < M; ++j) {
            update(temp[i+j],f[i],g[j]);
            update(temp[i+j+1],f[i],pll(g[j].first+(g[j].second>0),0));
        }
    for(int i = 0 ; i < n+m && i < M ; ++i) f[i] = temp[i];
    n += m;
}

void dfs(int u,int p) {
    sz[u] = 1;
    f[u][0] = pll(0,w[u]-b[u]);
    for(auto v : e[u]) if(v != p) {
        dfs(v,u);
        merge(f[u],sz[u],f[v],sz[v]);
    }
}

void solve() {
    cin >> n >> M;
    for(int i = 1 ; i <= n ; ++i)
        e[i].clear();
    for(int i = 1 ; i <= n ; ++i)
        cin >> b[i];
    for(int i = 1 ; i <= n ; ++i)
        cin >> w[i];
    for(int i = 1 ; i < n ; ++i) {
        int u,v;
        cin >> u >> v;
        e[u].pb(v);
        e[v].pb(u);
    }
    dfs(1,0);
    cout << f[1][M-1].first+(f[1][M-1].second>0) << endl;
}

int main() {
#ifdef LOCAL
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int T;
    scanf("%d",&T);
    while(T--) solve();
}