#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
const long long inf = 3000'000'000'001LL;

vector<int> nei[3001];
pair<int, long long> dp[3001][3001];
int a[3001];
int sz[3001];

template<class T1, class T2>
inline ostream& operator<<(ostream& ostr, const pair<T1, T2>& a)
{
    return ostr << "{" << a.first << ", " << a.second << "}";
}
void DFS(int v, int par = -1)
{
    sz[v] = 1;
    for (int to: nei[v])
        if (to != par)
        {
            DFS(to, v);
            sz[v] += sz[to];
        }
    int bound = 1;
    dp[v][1] = {a[v] > 0, a[v]};
    /*for (int i = 2; i <= sz[v]; ++i)
        dp[v][i] = {-1000'000, -inf};*/
    for (int to: nei[v])
    {
        if (to == par) continue;
        bound += sz[to];
        vector<pair<int, long long> > upd(bound + 1, {-1000'000, -inf});
        for (int i = 1; i <= bound; ++i)
            for (int j = 1; j <= min(sz[to], i); ++j)
            {
                // if (v == 2 && i == 3)
                    // cerr << "";
                pair<int, long long> curdp;
                curdp.second = dp[v][i - j + 1].second + dp[to][j].second;
                curdp.first = dp[v][i - j + 1].first + dp[to][j].first;
                curdp.first -= (dp[v][i - j + 1].second > 0);
                curdp.first -= (dp[to][j].second > 0);
                curdp.first += (curdp.second > 0);
                upd[i] = max(upd[i], curdp);
                if (i - j <= 0) continue;
                curdp = {dp[v][i - j].first + dp[to][j].first, dp[v][i - j].second};
                upd[i] = max(upd[i], curdp);
            }
        for (int i = 1; i <= bound; ++i)
            dp[v][i] = upd[i];
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        for (int i = 1; i <= n; ++i)
        {
            nei[i].clear();
            for (int j = 0; j <= 3000; ++j)
                dp[i][j] = {-1000'000, -inf};
        }
        for (int i = 1; i <= n; ++i)
        {
            cin >> a[i];
            a[i] *= -1;
        }
        for (int i = 1; i <= n; ++i)
        {
            int temp;
            cin >> temp;
            a[i] += temp;
        }
        for (int i = 1; i < n; ++i)
        {
            int u, v;
            cin >> u >> v;
            nei[u].push_back(v);
            nei[v].push_back(u);
        }
        srand(7979);
        int root = rand() % n + 1;
        DFS(root);
        /*for (int v = 1; v <= n; ++v)
            for (int i = 1; i <= sz[v]; ++i)
                cerr << "dp[" << v << "][" << i << "] = " << dp[v][i] << '\n';*/
        cout << dp[root][m].first << '\n';
    }
}
