/*
❤️❤️❤️I_love_QMsh❤️❤️❤️
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define x first
#define y second

using namespace std;
using namespace __gnu_pbds; // gp_hash_table<int, int> table;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // <int> .find_by_order(int) .order_of_key(int)

template<typename T> bool smin(T &a, const T &b) { bool ret = b < a; return a = (ret ? b : a), ret; }
template<typename T> bool smax(T &a, const T &b) { bool ret = a < b; return a = (ret ? b : a), ret; }

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

mt19937 rnd;

const int N = 3030;
const pair<int, ll> NEU = {0, LLONG_MIN / 4};
vector<int> g[N];
pair<int, ll> dp[N][N];
int sz[N];
int a[N];

pair<int, ll> operator +(const pair<int, ll> &a, const pair<int, ll> &b) {
  return {a.x + b.x, a.y};
}

pair<int, ll> operator -(const pair<int, ll> &a, const pair<int, ll> &b) {
  return {a.x + b.x - (a.y > 0) - (b.y > 0) + ((a.y + b.y) > 0), a.y + b.y};
}


void dfs(int u, int p) {
  for (int v : g[u]) {
    if (v != p) {
      dfs(v, u);
    }
  }

  sz[u] = 1;
  dp[u][1] = {a[u] > 0, a[u]};
  for (int v : g[u]) {
    if (v != p) {
      vector<pair<int, ll>> new_dp(sz[u] + sz[v] + 1, NEU);
      for (int i = 1; i <= sz[u]; i++) {
        for (int j = 1; j <= sz[v]; j++) {
          smax(new_dp[i + j], dp[u][i] + dp[v][j]);
          smax(new_dp[i + j - 1], dp[u][i] - dp[v][j]);
        }
        for (int i = 1; i <= sz[u] + sz[v]; i++) {
          dp[u][i] = new_dp[i];
        }
      }
      sz[u] += sz[v];
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      dp[i][j] = NEU;
    }
    sz[i] = 0;
    g[i].clear();
    a[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[i] -= x;
  }
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[i] += x;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, -1);
  cout << dp[1][m].x  << "\n";
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}