#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
struct node {
  long long r, l;
  node(long long r, long long l) : r(r), l(l) {}
  node() : r(), l() {}
  bool operator<(const node& o) const {
    if (r == o.r)
      return l < o.l;
    else
      return r < o.r;
  }
  node operator+(const node& o) const { return node(r + o.r, l + o.l); }
} dp[maxn][maxn], g[maxn];
vector<int> E[maxn], E2[maxn];
int e[2][maxn] = {1,  25, 2,  8,  3,  35, 4,  28, 5,  29, 5,  16, 6,  29,
                  7,  33, 8,  30, 8,  24, 9,  17, 9,  21, 10, 18, 10, 28,
                  10, 33, 11, 20, 12, 13, 12, 20, 13, 31, 13, 22, 13, 35,
                  14, 22, 15, 32, 15, 33, 17, 24, 18, 19, 23, 29, 23, 33,
                  25, 34, 26, 29, 27, 33, 29, 35, 30, 34, 34, 35};
int bb[maxn] = {
    28530167,  185244144, 681335998, 91458241,  851385120, 503949225, 518858842,
    712992285, 586745481, 957375672, 123450580, 40918933,  731279260, 237094228,
    183288105, 357785131, 450619968, 812208437, 266738488, 135278385, 411517534,
    938282644, 1303256,   319299683, 3552999,   565857743, 259261399, 433401562,
    823407462, 377670823, 556309397, 423544437, 367520989, 70642885};
int ww[maxn] = {
    27738449,  185086224, 681023852, 92361286,  851286576, 503438090, 519878933,
    712383850, 586496272, 958877164, 122955919, 39942040,  730929694, 236367212,
    183751520, 357101560, 449731009, 812397800, 265950811, 133887573, 411583592,
    936945307, 1318706,   318413756, 3328751,   565432613, 260262533, 435081373,
    823592370, 377024438, 555857637, 424043985, 368944490, 69935394};
long long siz[maxn], w[maxn], b[maxn];
int n, m;
void dfs(int x, int fa) {
  dp[x][1] = node(0, w[x] - b[x]);
  if (dp[x][1].l > 0) dp[x][1].r++;
  siz[x] = 1;
  for (auto i : E[x]) {
    if (i == fa) continue;
    dfs(i, x);
    for (int j = 1; j <= siz[x] + siz[i]; j++) g[j] = node(-1, 0);
    for (int j = 1; j <= siz[x]; j++) {
      for (int k = 1; k <= siz[i]; k++) {
        node t1, t2;
        t1 = t2 = dp[i][k];
        if (dp[x][j].l > 0 && t1.l > 0) t1.r--;
        if (dp[x][j].l + t1.l <= 0 && (dp[x][j].l > 0 || t1.l > 0)) t1.r--;
        t2.l = 0;
        g[j + k - 1] = max(g[j + k - 1], dp[x][j] + t1);
        g[j + k] = max(g[j + k], dp[x][j] + t2);
      }
    }
    siz[x] += siz[i];
    for (int j = 1; j <= siz[x]; j++) dp[x][j] = g[j];
  }
}
void getdata() {
  for (int i = 1; i <= n; i++) {
    cout << "##" << i << " ";
    for (auto j : E[i]) cout << j << " ";
    cout << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      E[i].clear();
      for (int j = 1; j <= n; j++) dp[i][j] = node(-1, 0);
    }
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) cin >> w[i];
    for (int i = 1; i < n; i++) {
      int x, y;
      cin >> x >> y;
      E[x].push_back(y);
      E[y].push_back(x);
    }
    dfs(1, 0);
    cout << dp[1][m].r << '\n';
  }
}
