#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);
const long long INFLL = (1ll << 60);
const long long MOD = (long long)(1e9 + 7);
void mul_mod(long long& a, long long b) {
  a *= b;
  a %= MOD;
}
void add_mod(long long& a, long long b) {
  a = (a < MOD) ? a : (a - MOD);
  b = (b < MOD) ? b : (b - MOD);
  a += b;
  a = (a < MOD) ? a : (a - MOD);
}
pair<int, long long> dp[3030][3030], sp[3030][3030];
long long w[3030], b[3030];
int ch[3030], m;
vector<int> g[3030];
void solve(int v, int p = -1) {
  int i, j, k, u;
  pair<int, long long> tmp;
  for (i = (g[v].size() - 1); i >= 0; --i) {
    if (g[v][i] == p) {
      g[v].erase(g[v].begin() + i);
      break;
    }
  }
  for (i = (g[v].size() - 1); i >= 0; --i) {
    u = g[v][i];
    solve(u, v);
  }
  sp[g[v].size()][1] = pair<int, long long>(0, w[v] - b[v]);
  ch[v] = 1;
  for (i = (g[v].size() - 1); i >= 0; --i) {
    u = g[v][i];
    for (j = 1; j <= ch[v]; ++j) {
      for (k = 1; k <= ch[u]; ++k) {
        sp[i][j + k - 1] = pair<int, long long>(0, -INFLL);
        sp[i][j + k] = pair<int, long long>(0, -INFLL);
      }
    }
    for (j = 1; j <= ch[v]; ++j) {
      for (k = 1; k <= ch[u]; ++k) {
        tmp = pair<int, long long>(sp[i + 1][j].first + dp[u][k].first,
                                   sp[i + 1][j].second + dp[u][k].second);
        sp[i][j + k - 1] = max(sp[i][j + k - 1], tmp);
        tmp = pair<int, long long>(sp[i + 1][j].first + dp[u][k].first +
                                       ((dp[u][k].second > 0ll) ? 1 : 0),
                                   sp[i + 1][j].second);
        sp[i][j + k] = max(sp[i][j + k], tmp);
      }
    }
    ch[v] += ch[u];
  }
  for (j = 1; j <= ch[v]; ++j) {
    dp[v][j] = sp[0][j];
  }
}
int main(void) {
  int t, n, i, j, u, v, ans;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (i = 0; i < n; ++i) {
      scanf("%lld", &b[i]);
    }
    for (i = 0; i < n; ++i) {
      scanf("%lld", &w[i]);
    }
    for (i = 1; i < n; ++i) {
      scanf("%d%d", &u, &v);
      --u;
      --v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    solve(0);
    ans = (dp[0][m].first + (dp[0][m].second > 0ll ? 1 : 0));
    for (i = 0; i < n; ++i) {
      g[i].clear();
    }
    printf("%d\n", ans);
  }
  return 0;
}
