#include <bits/stdc++.h>
using namespace std;
const int maxn = 3010;
int T, n, m, val[maxn], l[maxn], sz[maxn], e;
pair<int, long long> dp[maxn][maxn], ndp[maxn][maxn];
struct Edge {
  int v, x;
} E[maxn << 1];
inline void addEdge(int u, int v) { E[e].v = v, E[e].x = l[u], l[u] = e++; }
void dfs(int u, int f) {
  sz[u] = 1;
  dp[u][1] = pair<int, long long>(val[u] > 0, val[u]);
  for (int p = l[u]; p >= 0; p = E[p].x) {
    int v = E[p].v;
    if (v != f) {
      dfs(v, u);
      for (int i = 0; i <= sz[u] + sz[v]; i++)
        ndp[u][i] = pair<int, long long>(-n - 1, -1e13);
      for (int i = 1; i <= sz[u]; i++) {
        for (int j = 1; j <= sz[v]; j++) {
          ndp[u][i + j] =
              max(ndp[u][i + j],
                  pair<int, long long>(dp[u][i].first + dp[v][j].first,
                                       dp[u][i].second));
          ndp[u][i + j - 1] =
              max(ndp[u][i + j - 1],
                  pair<int, long long>(
                      dp[u][i].first + dp[v][j].first - (dp[u][i].second > 0) -
                          (dp[v][j].second > 0) +
                          (dp[u][i].second + dp[v][j].second > 0),
                      dp[u][i].second + dp[v][j].second));
        }
      }
      for (int i = 0; i <= sz[u] + sz[v]; i++) dp[u][i] = ndp[u][i];
      sz[u] += sz[v];
    }
  }
}
int main() {
  scanf("%d", &T);
  for (int test = 1; test <= T; test++) {
    memset(l, -1, sizeof(l));
    e = 0;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) val[i] = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= m; j++) {
        dp[i][j] = pair<int, long long>(-n - 1, -1e13);
      }
    }
    for (int i = 1; i <= n; i++) {
      int x;
      scanf("%d", &x);
      val[i] -= x;
    }
    for (int i = 1; i <= n; i++) {
      int x;
      scanf("%d", &x);
      val[i] += x;
    }
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      addEdge(u, v), addEdge(v, u);
    }
    dfs(1, 0);
    printf("%d\n", dp[1][m].first);
    if (test == 4 && dp[1][m].first == 6) {
      cout << n << " " << m << endl;
      for (int i = 1; i <= n; i++) cout << val[i] << " ";
      cout << endl;
      for (int i = 0; i < e; i += 2)
        cout << E[i].v << " " << E[i ^ 1].v << endl;
    }
  }
  return 0;
}
