#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void chkmax(T& a, T b) {
  if (a < b) a = b;
}
const long long INF = (long long)1e18;
const int N = 3030;
const int M = 3030;
int a[N];
int sz[N];
vector<int> g[N];
pair<int, long long> dp[N][2][M];
pair<int, long long> merge1(pair<int, long long> a, pair<int, long long> b) {
  return {a.first + b.first, a.second};
}
pair<int, long long> merge2(pair<int, long long> a, pair<int, long long> b) {
  pair<int, long long> res = {0, 0};
  res.first += a.first - (int)(a.second > 0);
  res.first += b.first - (int)(b.second > 0);
  res.second = a.second + b.second;
  res.first += (int)(res.second > 0);
  return res;
}
void dfs(int v, int p, int m) {
  sz[v] = 1;
  for (int i = 0; i <= m; ++i) dp[v][0][i] = {-N, -INF};
  dp[v][0][1] = {a[v] > 0, a[v]};
  for (int u : g[v]) {
    if (u == p) continue;
    dfs(u, v, m);
    sz[v] += sz[u];
    for (int i = 0; i <= m; ++i) dp[v][1][i] = {-N, -INF};
    for (int i = min(m, sz[v]); i > 0; --i) {
      for (int j = 1; j <= i && j <= sz[u]; ++j) {
        chkmax(dp[v][1][i], merge1(dp[v][0][i - j], dp[u][0][j]));
        chkmax(dp[v][1][i], merge2(dp[v][0][i - j + 1], dp[u][0][j]));
      }
    }
    swap(dp[v][0], dp[v][1]);
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int v = 1; v <= n; ++v) {
      g[v].clear();
    }
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i) {
      int x;
      scanf("%d", &x);
      a[i] -= x;
    }
    for (int i = 1; i < n; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(1, -1, m);
    printf("%d\n", dp[1][0][m].first);
  }
}
