#include <bits/stdc++.h>
using namespace std;
int N, M, T, sz[3005];
pair<int, long long> dp[3005][3005], m[3005];
vector<int> edges[3005];
long long arr[3005];
inline pair<int, long long> operator+(pair<int, long long> &a,
                                      pair<int, long long> &b) {
  return {a.first + b.first, a.second + b.second};
}
void solve(int x, int p) {
  sz[x] = 1;
  dp[x][1] = {0, arr[x]};
  for (int i = 2; i <= N; ++i) {
    dp[x][i] = {0, -1e18};
  }
  for (int i = 0; i < edges[x].size(); ++i) {
    int next = edges[x][i];
    if (next == p) continue;
    solve(next, x);
    for (int j = 1; j <= N; ++j) {
      m[j] = {0, -1e18};
    }
    for (int j = 1; j <= sz[x]; ++j) {
      for (int k = 1; k <= sz[next] && j + k - 1 <= M; ++k) {
        m[j + k - 1] = max(m[j + k - 1], dp[x][j] + dp[next][k]);
        m[j + k] = max(m[j + k], {(dp[next][k].second > 0) + dp[next][k].first +
                                      dp[x][j].first,
                                  dp[x][j].second});
      }
    }
    sz[x] += sz[next];
    for (int j = 1; j <= M && j <= sz[x]; ++j) {
      dp[x][j] = m[j];
    }
  }
  return;
}
int main() {
  cin >> T;
  while (T--) {
    cin >> N >> M;
    for (int i = 1; i <= N; ++i) {
      cin >> arr[i];
      edges[i].clear();
    }
    for (int i = 1; i <= N; ++i) {
      long long cur;
      cin >> cur;
      arr[i] = cur - arr[i];
    }
    for (int i = 0; i < N - 1; ++i) {
      int a, b;
      cin >> a >> b;
      edges[a].push_back(b);
      edges[b].push_back(a);
    }
    solve(1, 0);
    cout << dp[1][M].first + (dp[1][M].second > 0) << endl;
  }
  return 0;
}
