#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const long long OO = 0x3f3f3f3f3f3f3f3fLL;
const int oo = 0x3f3f3f3f;
const int maxn = 3010;
int n, m;
int a[maxn + 5];
vector<int> adj[maxn + 5];
int sz[maxn + 5];
long long sum[maxn + 5];
pair<int, long long> dp[maxn + 5][maxn + 5];
void dfs(int first, int f = -1) {
  dp[first][0] = make_pair(0, 0);
  for (int i = (1), i_end_ = (m + 1); i < i_end_; ++i)
    dp[first][i] = make_pair(0, -OO);
  sz[first] = 1;
  sum[first] = a[first];
  for (auto second : adj[first]) {
    if (second != f) {
      dfs(second, first);
      for (int i = sz[first] - 1; i >= 0; --i)
        for (int j = (0), j_end_ = (sz[second] + 1); j < j_end_; ++j)
          chkmax(dp[first][i + j],
                 make_pair(dp[first][i].first + dp[second][j].first,
                           dp[first][i].second + dp[second][j].second));
      sz[first] += sz[second];
      sum[first] += sum[second];
    }
  }
  for (int i = m - 1; i >= 0; --i) {
    auto tmp =
        make_pair(dp[first][i].first + ((sum[first] + dp[first][i].second) > 0),
                  -sum[first]);
    if (~f)
      chkmax(dp[first][i + 1], tmp);
    else
      dp[first][i + 1] = tmp;
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
      int first;
      scanf("%d", &first);
      a[i] = -first;
    }
    for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
      int first;
      scanf("%d", &first);
      a[i] = a[i] + first;
    }
    for (int i = (0), i_end_ = (n); i < i_end_; ++i) adj[i].clear();
    for (int i = (0), i_end_ = (n - 1); i < i_end_; ++i) {
      int u, v;
      scanf("%d%d", &u, &v), --u, --v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    dfs(0);
    printf("%d\n", dp[0][m].first);
  }
  return 0;
}
