#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const long long INF = 1e9;
const int MAXN = 100010;
int T;
int N, M;
int U[MAXN + 1], V[MAXN + 1];
bool vis[MAXN + 1];
long long val[MAXN + 1];
int fa[MAXN + 1];
inline int find(int x) { return (x == fa[x] ? x : (fa[x] = find(fa[x]))); }
inline void merge(int u, int v) {
  val[find(u)] += val[find(v)];
  fa[find(v)] = find(u);
}
int main() {
  T = read();
  while (T--) {
    N = read(), M = read();
    int ans = 0;
    for (int i = 1; i <= N; i++) {
      int x = read();
      val[i] = -x;
    }
    for (int i = 1; i <= N; i++) {
      int x = read();
      val[i] += x;
      ans += (val[i] > 0);
    }
    for (int i = 1; i < N; i++) {
      int u = read(), v = read();
      U[i] = u;
      V[i] = v;
      vis[i] = 0;
    }
    for (int i = 1; i <= N; i++) fa[i] = i;
    for (int i = N; i > M; i--) {
      int id1 = 0, id2 = 0, yes = 0;
      long long pre = -INF, now = -INF;
      for (int j = 1; j < N; j++) {
        int u = U[j], v = V[j];
        if (vis[j]) continue;
        int t1 = val[find(u)], t2 = val[find(v)];
        if (t1 > 0 && t2 > 0) {
          if (t1 + t2 > pre) {
            pre = t1 + t2;
            id1 = j;
          }
          continue;
        }
        if (t1 <= 0 && t2 <= 0) {
          yes = 1;
          id1 = j;
          break;
        }
        if (t1 + t2 > now) {
          now = t1 + t2;
          id2 = j;
        }
      }
      if (yes) {
        merge(U[id1], V[id1]);
        vis[id1] = 1;
        continue;
      }
      if (now > 0 && id2) {
        merge(U[id2], V[id2]);
        vis[id2] = 1;
        continue;
      }
      if (id1) {
        --ans;
        merge(U[id1], V[id1]);
        vis[id1] = 1;
      } else {
        --ans;
        merge(U[id2], V[id2]);
        vis[id2] = 1;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
