#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 7;
int t, n, m, b[N], w[N], a[N];
vector<int> e[N];
pair<int, long long> f[N][N], tmp[N];
int sz[N];
inline void add(int a, int b) {
  e[a].push_back(b);
  e[b].push_back(a);
}
inline void update(pair<int, long long> &a, pair<int, long long> b) {
  if (a.first < b.first)
    a = b;
  else if (a.first == b.first && a.second < b.second)
    a = b;
}
void dfs(int u, int fa) {
  sz[u] = 1;
  f[u][1] = pair<int, long long>(0, a[u]);
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    if (v == fa) continue;
    dfs(v, u);
    for (int j = 1; j <= sz[u] + sz[v]; j++)
      tmp[j] = pair<int, long long>(-1, 0);
    for (int j = 1; j <= sz[u]; j++)
      for (int k = 1; k <= sz[v]; k++) {
        update(tmp[j + k], pair<int, long long>(f[u][j].first + f[v][k].first +
                                                    (f[v][k].second > 0),
                                                f[u][j].second));
        update(tmp[j + k - 1],
               pair<int, long long>(f[u][j].first + f[v][k].first,
                                    f[u][j].second + f[v][k].second));
      }
    for (int j = 1; j <= sz[u] + sz[v]; j++) f[u][j] = tmp[j];
    sz[u] += sz[v];
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &w[i]), a[i] = w[i] - b[i];
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      add(u, v);
    }
    dfs(1, 0);
    printf("%d\n", f[1][m].first + (f[1][m].second > 0));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= sz[i]; j++) f[i][j] = pair<int, long long>(0, 0);
      e[i].clear();
    }
  }
  return 0;
}
