#include <bits/stdc++.h>
using namespace std;
namespace Patchouli {
const int N = 3200;
inline int check(int x) { return x > 0; }
struct node {
  long long a, b;
  inline bool operator<(const node &b) const {
    return this->a ^ b.a ? this->a < b.a : this->b < b.b;
  }
  node(const int _a, const int _b) {
    a = _a;
    b = _b;
  }
  inline node operator+(const node &b) const {
    return node(this->a + b.a + check(b.b), this->b);
  }
  inline node operator*(const node &b) const {
    return node(this->a + b.a, this->b + b.b);
  }
  node() {}
} f[N][N], tmp[N];
const node inf = node(-114514, -114514);
int n, m;
int head[N], ver[N * 2], next[N * 2], tot;
int size[N];
long long a[N];
inline void add(int x, int y) {
  next[++tot] = head[x], head[x] = tot, ver[tot] = y;
  next[++tot] = head[y], head[y] = tot, ver[tot] = x;
}
void dfs(int x, int father) {
  size[x] = 1;
  f[x][1] = node(0, a[x]);
  for (int i = head[x]; i; i = next[i]) {
    if (ver[i] == father) continue;
    dfs(ver[i], x);
    int limit = min(size[x] + size[ver[i]], m);
    for (int j = 1; j <= limit; ++j) tmp[j] = inf;
    for (int j = 1, limitj = min(size[x], m); j <= limitj; ++j)
      for (int k = 1, limitk = min(size[ver[i]], m + 1 - j); k <= limitk; ++k) {
        tmp[j + k] = max(tmp[j + k], f[x][j] + f[ver[i]][k]);
        tmp[j + k - 1] = max(tmp[j + k - 1], f[x][j] * f[ver[i]][k]);
      }
    for (int j = 1; j <= limit; ++j) f[x][j] = tmp[j];
    size[x] += size[ver[i]];
  }
}
inline int read() {
  int a = 1, b = 0;
  char t;
  do {
    t = getchar();
    if (t == '-') a = -1;
  } while (t > '9' || t < '0');
  do {
    b = b * 10 - '0' + t;
    t = getchar();
  } while (t >= '0' && t <= '9');
  return a * b;
}
int QAQ() {
  int T = read();
  while (T--) {
    n = read(), m = read();
    for (int i = 1; i <= n; ++i) head[i] = 0;
    tot = 0;
    for (int i = 1; i <= n; ++i) a[i] = -read();
    for (int i = 1; i <= n; ++i) a[i] += read();
    for (int i = 1; i < n; ++i) add(read(), read());
    dfs(1, 0);
    printf("%d\n", f[1][m].a + check(f[1][m].b));
  }
  return false;
}
}  // namespace Patchouli
int main() { return Patchouli::QAQ(); }
