#include <bits/stdc++.h>
using namespace std;
int t;
int n, m;
pair<int, long long> f[3086][3086];
vector<int> v[3086];
int x, y;
int a[3086];
int siz[3086];
inline pair<int, long long> operator+(pair<int, long long> a,
                                      pair<int, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
void dfs(int i, int fa) {
  siz[i] = 1;
  f[i][1] = {0, a[i]};
  for (int j = 0; j < v[i].size(); j++) {
    int to = v[i][j];
    if (to == fa) continue;
    dfs(to, i);
    siz[i] += siz[to];
    for (int l = min(siz[i], m); l; l--) {
      for (int k = 1; k <= min(siz[to], m) && l - k + 1; k++) {
        f[i][l] = f[i][l - k + 1] + f[to][k];
        if (l - k)
          f[i][l] =
              max(f[i][l],
                  f[i][l - k] + (pair<int, long long>){
                                    f[to][k].first + (f[to][k].second > 0), 0});
      }
    }
  }
  for (int j = min(siz[i], m); j; j--) {
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &x);
      a[i] = -a[i] + x;
      v[i].clear();
      for (int j = 1; j <= n; j++) f[i][j] = {-1e9, -1e18};
    }
    for (int i = 1; i < n; i++) {
      scanf("%d%d", &x, &y);
      v[x].push_back(y), v[y].push_back(x);
    }
    dfs(1, 0);
    printf("%d\n", f[1][m].first + (f[1][m].second > 0));
  }
}
