#include <bits/stdc++.h>
using namespace std;
int n;
int diff[3000];
vector<int> adjList[3000];
int size[3000];
pair<int, long long int> dp[3000][3000], dp2[3000][3000];
int doDFS(int u, int p) {
  int i, j, k;
  vector<int> c;
  size[u] = 1;
  for (i = 0; i < adjList[u].size(); i++) {
    int v = adjList[u][i];
    if (v != p) size[u] += doDFS(v, u), c.push_back(v);
  }
  int sum = 0;
  for (i = 0; i < c.size(); i++) {
    int v = c[i];
    if (i == 0) {
      dp2[0][0] = make_pair(0, -1e18);
      for (j = 0; j < size[v]; j++) {
        dp2[0][0] =
            max(dp2[0][0], make_pair(dp[v][j].first + (dp[v][j].second > 0),
                                     (long long int)diff[u]));
        dp2[0][j + 1] = make_pair(dp[v][j].first, dp[v][j].second + diff[u]);
      }
    } else {
      for (j = 0; j <= sum + size[v]; j++) dp2[i][j] = make_pair(0, -1e18);
      for (j = 0; j <= sum; j++) {
        for (k = 0; k < size[v]; k++) {
          dp2[i][j + k + 1] =
              max(dp2[i][j + k + 1],
                  make_pair(dp2[i - 1][j].first + dp[v][k].first,
                            dp2[i - 1][j].second + dp[v][k].second));
          dp2[i][j + k] = max(dp2[i][j + k],
                              make_pair(dp2[i - 1][j].first + dp[v][k].first +
                                            (dp[v][k].second > 0),
                                        dp2[i - 1][j].second));
        }
      }
    }
    sum += size[v];
  }
  if (c.empty())
    dp[u][0] = make_pair(0, diff[u]);
  else
    for (i = 0; i <= sum; i++) dp[u][i] = dp2[c.size() - 1][i];
  return size[u];
}
int main() {
  int i;
  int t, w, m, u, v;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &n, &m);
    for (i = 0; i < n; i++) scanf("%d", &diff[i]);
    for (i = 0; i < n; i++) scanf("%d", &w), diff[i] = w - diff[i];
    for (i = 0; i < n - 1; i++) {
      scanf("%d %d", &u, &v);
      u--, v--;
      adjList[u].push_back(v);
      adjList[v].push_back(u);
    }
    doDFS(0, -1);
    printf("%d\n", dp[0][n - m].first + (dp[0][n - m].second > 0));
    for (i = 0; i < n; i++) adjList[i].clear();
  }
  return 0;
}
