#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3c3c3c3c;
const long long LINF = 1ll * INF * INF * 2;
const int N = 5001;
int n, m, a, b;
int x[N], y[N];
vector<int> v[N];
vector<int> dfn;
pair<int, int> ans[N][N];
int s[N];
pair<int, int> nans[N];
int dfs(int prv, int cur) {
  dfn.push_back(cur);
  for (int i = 0; i < ((int)((v[cur]).size())); i++)
    if (v[cur][i] == prv) {
      v[cur].erase(v[cur].begin() + i);
      break;
    }
  s[cur] = 1;
  for (int nxt : v[cur]) {
    s[cur] += dfs(cur, nxt);
  }
  return s[cur];
}
void clear() {
  for (int i = 1; i <= n; i++) v[i].clear();
  dfn.clear();
}
inline void mm(pair<int, int> &x, pair<int, int> y) { x = min(x, y); }
int T;
void proc() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", x + i);
  for (int i = 1; i <= n; i++) scanf("%d", y + i);
  for (int i = 1; i <= n; i++) x[i] = x[i] - y[i];
  if (T == 81) {
    printf("%d/%d/", n, m);
    for (int i = 1; i <= n; i++) printf("%d/", x[i]);
    for (int i = 1; i < n; i++) {
      scanf("%d%d", &a, &b);
      v[a].push_back(b);
      v[b].push_back(a);
      if (T == 81) printf("%d %d/", a, b);
    }
    dfs(0, 1);
    reverse((dfn).begin(), (dfn).end());
  }
  for (int i : dfn) {
    for (int j = 1; j <= n; j++) ans[i][j] = {INF, INF};
    if (x[i] < 0)
      ans[i][1] = {-1, x[i]};
    else
      ans[i][1] = {0, x[i]};
    int num = 1;
    for (int nxt : v[i]) {
      for (int j = 1; j <= s[nxt] + num; j++) nans[j] = {INF, INF};
      for (int j = 1; j <= s[nxt]; j++) {
        for (int k = 1; k <= num; k++) {
          pair<int, int> p1 = ans[nxt][j];
          pair<int, int> p2 = ans[i][k];
          int c1 = p1.first;
          int c2 = p2.first;
          int v1 = p1.second;
          int v2 = p2.second;
          mm(nans[j + k], {c1 + c2, v2});
          mm(nans[j + k - 1],
             {c1 + c2 + (v1 < 0) + (v2 < 0) - (v1 + v2 < 0), v1 + v2});
        }
      }
      num += s[nxt];
      for (int j = 1; j <= num; j++) ans[i][j] = nans[j];
    }
  }
  printf("%d\n", -ans[1][m].first);
}
int main(void) {
  int TC;
  scanf("%d", &TC);
  while (TC--) {
    T++;
    proc();
    clear();
  }
}
