#include <bits/stdc++.h>
using namespace std;
template <typename TYPE>
inline void chkmax(TYPE &first, TYPE second) {
  first < second ? first = second : TYPE();
}
template <typename TYPE>
inline void chkmin(TYPE &first, TYPE second) {
  second < first ? first = second : TYPE();
}
template <typename TYPE>
void readint(TYPE &first) {
  first = 0;
  int f = 1;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) first = first * 10 + c - '0';
  first *= f;
}
const int MAXN = 3005;
int n, m, a[MAXN], size[MAXN];
vector<int> G[MAXN];
pair<int, long long> f[MAXN][MAXN], g[MAXN];
inline pair<int, long long> operator+(pair<int, long long> a,
                                      pair<int, long long> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
void dfs(int u, int pa) {
  for (int i = 0; i <= n; ++i) f[u][i] = make_pair(0, a[u]);
  size[u] = 0;
  for (auto v : G[u]) {
    if (v == pa) continue;
    dfs(v, u);
    for (int i = 0; i <= size[u] + size[v] + 1; ++i) g[i] = make_pair(0, 0);
    for (int i = 0; i <= size[u]; ++i)
      for (int j = 0; j <= size[v]; ++j) {
        chkmax(g[i + j], f[u][i] + f[v][j]);
        chkmax(g[i + j + 1],
               make_pair(f[u][i].first + f[v][j].first + (f[v][j].second > 0),
                         f[u][i].second));
      }
    for (int i = 0; i <= size[u] + size[v] + 1; ++i) f[u][i] = g[i];
    size[u] += size[v];
  }
  ++size[u];
}
void solve() {
  int first, u, v;
  readint(n), readint(m);
  for (int i = 1; i <= n; ++i) readint(a[i]);
  for (int i = 1; i <= n; ++i) {
    readint(first);
    a[i] = first - a[i];
  }
  for (int i = 1; i < n; ++i) {
    readint(u), readint(v);
    G[u].push_back(v), G[v].push_back(u);
  }
  dfs(1, -1);
  printf("%d\n", f[1][m - 1].first + (f[1][m - 1].second > 0));
  for (int i = 1; i <= n; ++i) G[i].clear();
}
int main() {
  int T;
  readint(T);
  while (T--) solve();
  return 0;
}
