#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, next;
};
Edge E[6005];
int Ecou, head[3005];
int N, M;
int val[3005];
pair<int, long long> dp[3005][3005];
inline void init() {
  for (int i = 1; i <= N; ++i) head[i] = -1;
  Ecou = 0;
}
inline void addEdge(int u, int v) {
  E[Ecou].to = v;
  E[Ecou].next = head[u];
  head[u] = Ecou++;
}
inline int merge(long long a, long long b) {
  int ret = 0;
  if (a > 0) --ret;
  if (b > 0) --ret;
  if (a + b > 0) ++ret;
  return ret;
}
pair<int, long long> newdp[3005];
int dfs1(int u, int f) {
  int ret = 1;
  dp[u][1] = pair<int, long long>(0, val[u]);
  for (int i = head[u]; i != -1; i = E[i].next)
    if (E[i].to != f) {
      int tmp = dfs1(E[i].to, u);
      int v = E[i].to;
      for (int x = 1; x <= ret + tmp; ++x)
        newdp[x] = pair<int, long long>(-1, -1);
      for (int x = 1; x <= ret; ++x)
        for (int y = 1; y <= tmp; ++y) {
          newdp[x + y] = max(newdp[x + y], pair<int, long long>(
                                               dp[u][x].first + dp[v][y].first +
                                                   (dp[v][y].second > 0),
                                               dp[u][x].second));
          newdp[x + y - 1] =
              max(newdp[x + y - 1],
                  pair<int, long long>(dp[u][x].first + dp[v][y].first,
                                       dp[u][x].second + dp[v][y].second));
        }
      ret += tmp;
      for (int x = 1; x <= ret; ++x) dp[u][x] = newdp[x];
    }
  return ret;
}
inline pair<int, long long> mymax(const pair<int, long long>& a,
                                  const pair<int, long long>& b) {
  if (a.first != b.first) return a.first > b.first ? a : b;
  if (a.second > 0 && b.second <= 0) return b;
  if (a.second <= 0 && b.second > 0) return a;
  return a.second > b.second ? a : b;
}
int dfs(int u, int f) {
  int ret = 1;
  dp[u][1] = pair<int, long long>(val[u] > 0 ? 1 : 0, val[u]);
  for (int i = head[u]; i != -1; i = E[i].next)
    if (E[i].to != f) {
      int tmp = dfs(E[i].to, u);
      int v = E[i].to;
      for (int x = 1; x <= ret + tmp; ++x)
        newdp[x] = pair<int, long long>(-1, -1);
      for (int x = 1; x <= ret; ++x)
        for (int y = 1; y <= tmp; ++y) {
          newdp[x + y] =
              mymax(newdp[x + y],
                    pair<int, long long>(dp[u][x].first + dp[v][y].first,
                                         dp[u][x].second));
          newdp[x + y - 1] = mymax(
              newdp[x + y - 1],
              pair<int, long long>(dp[u][x].first + dp[v][y].first +
                                       merge(dp[u][x].second, dp[v][y].second),
                                   dp[u][x].second + dp[v][y].second));
        }
      ret += tmp;
      for (int x = 1; x <= ret; ++x) dp[u][x] = newdp[x];
    }
  return ret;
}
int main() {
  int first = -1;
  int T;
  scanf("%d", &T);
  for (int ttt = 0; ttt < T; ++ttt) {
    scanf("%d %d", &N, &M);
    init();
    for (int i = 1; i <= N; ++i) {
      scanf("%d", val + i);
      val[i] = -val[i];
      if (first == -1) first = -val[i];
    }
    for (int i = 1; i <= N; ++i) {
      int t;
      scanf("%d", &t);
      val[i] += t;
    }
    for (int i = 1; i < N; ++i) {
      int a, b;
      scanf("%d %d", &a, &b);
      addEdge(a, b);
      addEdge(b, a);
    }
    dfs(1, -1);
    printf("%d\n", dp[1][M].first);
  }
  return 0;
}
