#include <bits/stdc++.h>
using namespace std;
int n, m;
long long wasps[3010], bees[3010];
vector<int> adjl[3010];
int dlink[3010], rlink[3010];
int sub[3010], pr[3010];
int subch[3010];
void make_link(int u, int par) {
  vector<int> foo;
  for (int i = 0; i <= (int)adjl[u].size() - 1; i++) {
    int v = adjl[u][i];
    if (v == par) {
      continue;
    }
    foo.push_back(v);
  }
  if (foo.size()) {
    dlink[u] = foo[0];
  }
  for (int i = 0; i <= (int)foo.size() - 2; i++) {
    rlink[foo[i]] = foo[i + 1];
  }
  sub[u] = 1;
  for (int i = 0; i <= (int)adjl[u].size() - 1; i++) {
    int v = adjl[u][i];
    if (v == par) {
      continue;
    }
    make_link(v, u);
    sub[u] += sub[v];
    subch[v] += sub[u];
  }
  pr[u] = par;
}
pair<int, long long> take_ans(pair<int, long long> ans,
                              pair<int, long long> hol) {
  if (hol.first < ans.first) {
    return ans;
  }
  if (hol.first > ans.first) {
    return hol;
  }
  return {ans.first, max(ans.second, hol.second)};
}
int col;
int vis[3010][3010];
pair<int, long long> dp[3010][3010];
pair<int, long long> func(int u, int vil) {
  if (rlink[u] == 0 && dlink[u] == 0) {
    if (vil - 1 == 0) {
      if (wasps[u] - bees[u] > 0) {
        return {1, 0};
      } else {
        return {0, 0};
      }
    }
    if (vil == 0) {
      return {0, wasps[u] - bees[u]};
    }
    return {-1, 0};
  }
  if (vis[u][vil] == col) {
    return dp[u][vil];
  }
  pair<int, long long> ans = {-1, 0};
  int nvil;
  nvil = vil - 1;
  if (rlink[u] == 0) {
    pair<int, long long> tmp = func(dlink[u], vil - 1);
    if (tmp.first != -1 && tmp.second + wasps[u] - bees[u] > 0) {
      ans = take_ans(ans, {tmp.first + 1, 0});
    }
    if (tmp.first != -1 && tmp.second + wasps[u] - bees[u] <= 0) {
      ans = take_ans(ans, {tmp.first, 0});
    }
  }
  if (dlink[u] == 0) {
    pair<int, long long> tmp = func(rlink[u], vil - 1);
    if (tmp.first != -1 && wasps[u] - bees[u] > 0) {
      ans = take_ans(ans, {tmp.first + 1, tmp.second});
    }
    if (tmp.first != -1 && wasps[u] - bees[u] <= 0) {
      ans = take_ans(ans, {tmp.first, tmp.second});
    }
  }
  if (rlink[u] && dlink[u]) {
    for (int i = min(nvil, sub[u]); i >= 0; i--) {
      if (nvil - i > sub[pr[u]] - subch[u]) {
        break;
      }
      pair<int, long long> tmp1 = func(dlink[u], i);
      pair<int, long long> tmp2 = func(rlink[u], nvil - i);
      if (tmp1.first == -1 || tmp2.first == -1) {
        continue;
      }
      if (tmp1.second + wasps[u] - bees[u] > 0) {
        ans = take_ans(ans, {tmp1.first + tmp2.first + 1, tmp2.second});
      }
      if (tmp1.second + wasps[u] - bees[u] <= 0) {
        ans = take_ans(ans, {tmp1.first + tmp2.first, tmp2.second});
      }
    }
  }
  if (u != 1) {
    nvil = vil;
    if (rlink[u] == 0) {
      pair<int, long long> tmp = func(dlink[u], nvil);
      if (tmp.first != -1) {
        ans = take_ans(ans, {tmp.first, tmp.second + wasps[u] - bees[u]});
      }
    }
    if (dlink[u] == 0) {
      pair<int, long long> tmp = func(rlink[u], nvil);
      if (tmp.first != -1) {
        ans = take_ans(ans, {tmp.first, tmp.second + wasps[u] - bees[u]});
      }
    }
    for (int i = min(nvil, sub[u]); i >= 0; i--) {
      if (nvil - i > sub[pr[u]] - subch[u]) {
        break;
      }
      pair<int, long long> tmp1 = func(dlink[u], i);
      pair<int, long long> tmp2 = func(rlink[u], nvil - i);
      if (tmp1.first == -1 || tmp2.first == -1) {
        continue;
      }
      ans = take_ans(ans, {tmp1.first + tmp2.first,
                           tmp1.second + tmp2.second + wasps[u] - bees[u]});
    }
  }
  vis[u][vil] = col;
  return dp[u][vil] = ans;
}
int main() {
  int tc;
  scanf("%d", &tc);
  for (int tt = 1; tt <= tc; tt++) {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
      adjl[i].clear();
      dlink[i] = 0;
      rlink[i] = 0;
      sub[i] = 0;
      subch[i] = 0;
      pr[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &bees[i]);
    }
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &wasps[i]);
    }
    for (int i = 1; i <= n - 1; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      adjl[u].push_back(v);
      adjl[v].push_back(u);
    }
    make_link(1, 0);
    sub[0] = sub[1] + 1;
    col = tt;
    printf("%d\n", max(0, func(1, m).first));
  }
  return 0;
}
