#include <bits/stdc++.h>
using namespace std;
int main() {
  auto ma = [&](pair<long long, long long> &a, pair<long long, long long> b) {
    if (a.first < b.first)
      a = b;
    else if (a.first == b.first && a.second < b.second)
      a = b;
  };
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<int> b(n + 1), w(n + 1);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
    vector<vector<int>> v(n + 1);
    for (int i = 1; i < n; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      v[x].emplace_back(y);
      v[y].emplace_back(x);
    }
    vector<int> sz(n + 1);
    vector<pair<long long, long long>> tmp(n + 1);
    vector<vector<pair<long long, long long>>> dp(
        n + 1, vector<pair<long long, long long>>(n + 1));
    function<void(int, int)> dfs = [&](int u, int f) {
      sz[u] = 1;
      dp[u][1] = {0, w[u] - b[u]};
      for (auto x : v[u]) {
        if (x == f) continue;
        dfs(x, u);
        for (int i = 1; i <= sz[u] + sz[x]; i++) tmp[i] = {-1, 0};
        for (int i = 1; i <= sz[u]; i++)
          for (int j = 1; j <= sz[x]; j++) {
            ma(tmp[i + j],
               {dp[u][i].first + dp[x][j].first + (dp[x][j].second > 0),
                dp[u][i].second});
            ma(tmp[i + j - 1], {dp[u][i].first + dp[x][j].first,
                                dp[u][i].second + dp[x][j].second});
          }
        for (int i = 1; i <= sz[u] + sz[x]; i++) dp[u][i] = tmp[i];
        sz[u] += sz[x];
      }
    };
    dfs(1, 0);
    printf("%lld\n", dp[1][m].first + (dp[1][m].second > 0));
  }
  return 0;
}
