#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
struct edge {
  int to, next;
} e[N * 2];
int head[N], sz[N];
int n, m, tot, a[N], b[N];
pair<long long, long long> f[N][N], v[N];
pair<long long, long long> min(pair<long long, long long> a,
                               pair<long long, long long> b) {
  if (a.first != b.first) return a.first < b.first ? b : a;
  return a.second < b.second ? a : b;
}
pair<long long, long long> operator+(const pair<long long, long long> &a,
                                     const pair<long long, long long> &b) {
  return pair<long long, long long>(a.first + b.first, a.second + b.second);
}
pair<long long, long long> DDD(const pair<long long, long long> &a) {
  return pair<long long, long long>(a.first + (a.second < 0), 0);
}
void add(int x, int y) {
  e[++tot] = (edge){y, head[x]};
  head[x] = tot;
}
void dfs(int x, int fa) {
  sz[x] = 1;
  f[x][1] = pair<int, int>(0, b[x] - a[x]);
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa) {
      dfs(e[i].to, x);
      for (int j = (int)(1); j <= (int)(sz[x] + sz[e[i].to]); j++)
        v[j] = pair<long long, long long>(-1, 1ll << 60);
      for (int j = (int)(1); j <= (int)(sz[x]); j++)
        for (int k = (int)(1); k <= (int)(sz[e[i].to]); k++) {
          v[j + k] = min(v[j + k], f[x][j] + DDD(f[e[i].to][k]));
          v[j + k - 1] = min(v[j + k - 1], f[x][j] + f[e[i].to][k]);
        }
      sz[x] += sz[e[i].to];
      for (int j = (int)(1); j <= (int)(sz[x]); j++) f[x][j] = v[j];
    }
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[i]);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &b[i]);
  for (int i = (int)(1); i <= (int)(n); i++) head[i] = 0;
  tot = 0;
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  printf("%lld\n", DDD(f[1][m]).first);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
}
