#include <bits/stdc++.h>
using namespace std;
template <typename T>
void Min(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void Max(T &a, T b) {
  a = max(a, b);
}
const int mod = (int)1e9 + 7;
const long long inf = 2e16;
const int N = (int)3e3 + 15;
int n, m, t, a[N], sz[N];
vector<int> g[N];
pair<long long, long long> dp[N][N], tmp[N];
void dfs(int v, int p = -1) {
  sz[v] = 1;
  dp[v][1] = make_pair(0, a[v]);
  for (int to : g[v])
    if (to != p) {
      dfs(to, v);
      for (int i = 1; i <= sz[v]; ++i) tmp[i] = make_pair(0, -inf);
      for (int j = 1; j <= sz[to]; ++j)
        for (int i = sz[v]; i >= 1; --i) {
          Max(tmp[i + j], make_pair(dp[to][j].first + dp[v][i].first +
                                        (dp[to][j].second > 0),
                                    dp[v][i].second)),
              Max(tmp[i + j - 1],
                  make_pair(dp[to][j].first + dp[v][i].first,
                            dp[to][j].second + dp[v][i].second));
        }
      sz[v] += sz[to];
      for (int i = 1; i <= sz[v]; ++i) dp[v][i] = tmp[i];
    }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    for (int i = 0; i < N; ++i) {
      g[i].clear();
      for (int j = 0; j < N; ++j) dp[i][j] = make_pair(0, -inf);
    }
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1; i <= n; ++i) {
      int x;
      scanf("%d", &x);
      a[i] = x - a[i];
    }
    for (int i = 2; i <= n; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(1);
    printf("%lld\n", dp[1][m].first + (dp[1][m].second > 0));
  }
  return 0;
}
