#include <bits/stdc++.h>
using namespace std;
int n, m, w[3010], b[3010], sz[3010];
vector<int> adj[3010];
void remove_element(vector<int> &v, int el) {
  for (int i = 0; i < v.size(); i++) {
    if (v[i] != el) continue;
    for (int j = i; j + 1 < v.size(); j++) {
      swap(v[j], v[j + 1]);
    }
    v.pop_back();
    break;
  }
}
void dfs(int u, int par = 0) {
  remove_element(adj[u], par);
  sz[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    dfs(v, u);
    sz[u] += sz[v];
  }
}
pair<int, int> f1(int u, int m);
vector<pair<int, int> > memo2[3010][3010];
pair<int, int> f2(int u, int m, int c, int sz_after) {
  if (c == adj[u].size()) {
    return pair<int, int>(0, 0);
  }
  if (memo2[u][m][c].first != -1) {
    return memo2[u][m][c];
  }
  int v = adj[u][c];
  pair<int, int> ret = pair<int, int>(-1, 0);
  for (int i = max(0, m - sz_after + sz[v]); i <= min(m, sz[v]); i++) {
    if (i > 0) {
      pair<int, int> tmp1 = f1(v, i);
      if (tmp1.second > 0) tmp1.first++;
      pair<int, int> tmp2 = f2(u, m - i, c + 1, sz_after - sz[v]);
      ret = max(ret, pair<int, int>(tmp1.first + tmp2.first, tmp2.second));
    }
    if (i < sz[v]) {
      pair<int, int> tmp1 = f1(v, i + 1);
      pair<int, int> tmp2 = f2(u, m - i, c + 1, sz_after - sz[v]);
      ret = max(ret, pair<int, int>(tmp1.first + tmp2.first,
                                    tmp1.second + tmp2.second));
    }
  }
  return memo2[u][m][c] = ret;
}
pair<int, int> memo1[3010][3010];
pair<int, int> f1(int u, int m) {
  if (memo1[u][m].first != -1) return memo1[u][m];
  pair<int, int> ret = f2(u, m - 1, 0, sz[u] - 1);
  ret.second += w[u] - b[u];
  return memo1[u][m] = ret;
}
int main() {
  int t;
  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]);
    }
    for (int i = 0; i < n - 1; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    dfs(1);
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= m; j++) {
        memo1[i][j] = pair<int, int>(-1, -1);
        memo2[i][j].assign(adj[i].size(), pair<int, int>(-1, -1));
      }
    }
    pair<int, int> f = f1(1, m);
    int ans = f.first + (f.second > 0);
    printf("%d\n", ans);
    for (int i = 1; i <= n; i++) {
      adj[i].clear();
      for (int j = 0; j <= m; j++) {
        memo2[i][j].clear();
      }
    }
  }
}
