#include <bits/stdc++.h>
using namespace std;
const int maxn = 3030;
vector<int> to[maxn];
int f[2][maxn][maxn], tmp[2][maxn];
long long fp[2][maxn][maxn], tmpp[2][maxn];
long long b[maxn], w[maxn];
int sz[maxn];
void solve(int u, int p) {
  sz[u] = 1;
  f[0][u][0] = -maxn;
  fp[0][u][0] = -maxn;
  f[0][u][1] = w[u] > 0;
  fp[0][u][1] = 0;
  f[1][u][0] = 0;
  fp[1][u][0] = w[u];
  f[1][u][1] = -maxn;
  fp[1][u][1] = -maxn;
  for (int v : to[u]) {
    if (v == p) continue;
    solve(v, u);
    for (int i = 0; i <= sz[u] + sz[v]; i++)
      tmp[0][i] = tmpp[0][i] = tmp[1][i] = tmpp[1][i] = -maxn;
    for (int i = 0; i <= sz[u]; i++) {
      for (int j = 0; j <= sz[v]; j++) {
        for (int pi = 0; pi < 2; pi++) {
          for (int pj = 0; pj < 2; pj++) {
            if (!pi && pj) {
              continue;
            }
            int va = f[pi][u][i] + f[pj][v][j];
            long long vb = fp[pi][u][i] + fp[pj][v][j];
            int ni = pi | pj;
            if (tmp[ni][i + j] < va) {
              tmp[ni][i + j] = va;
              tmpp[ni][i + j] = vb;
            } else if (tmp[ni][i + j] == va && tmpp[ni][i + j] < vb) {
              tmpp[ni][i + j] = vb;
            }
            if (ni) {
              if (vb > 0) va++;
              vb = 0;
              ni = 0;
              if (tmp[ni][i + j + 1] < va) {
                tmp[ni][i + j + 1] = va;
                tmpp[ni][i + j + 1] = vb;
              } else if (tmp[ni][i + j + 1] == va && tmpp[ni][i + j + 1] < vb) {
                tmpp[ni][i + j + 1] = vb;
              }
            }
          }
        }
      }
    }
    sz[u] += sz[v];
    for (int i = 0; i <= sz[u]; i++) {
      f[0][u][i] = tmp[0][i];
      fp[0][u][i] = tmpp[0][i];
      f[1][u][i] = tmp[1][i];
      fp[1][u][i] = tmpp[1][i];
    }
  }
}
int main() {
  int t;
  scanf("%d", &t);
  ;
  while (t--) {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%lld", b + i);
    for (int i = 0; i < n; i++) scanf("%lld", w + i);
    ;
    for (int i = 0; i < n; i++) w[i] -= b[i];
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      u--;
      v--;
      to[u].push_back(v);
      to[v].push_back(u);
    }
    solve(0, -1);
    printf("%d\n", f[0][0][m]);
    for (int i = 0; i < n; i++) to[i].clear();
  }
  return 0;
}
