#include <bits/stdc++.h>
using namespace std;
const int maxn = 3007;
struct node {
 public:
  long long win;
  long long dt;
  node(long long a = 0, long long b = 0) { win = a, dt = b; }
  node operator+(const node& rhs) { return node(win + rhs.win, dt + rhs.dt); }
  bool operator<(const node& rhs) const {
    if (win != rhs.win) return win < rhs.win;
    return dt < rhs.dt;
  }
  node div() { return node(win + (int)(dt > 0)); }
};
void dfs(int u, int fa, vector<vector<int> >& edge, vector<vector<node> >& dp) {
  for (auto v : edge[u]) {
    if (v == fa) continue;
    dfs(v, u, edge, dp);
    vector<node> ndp(dp[u].size() + dp[v].size(), node(-1));
    for (int i = (0); i < (dp[u].size()); i++) {
      for (int j = (0); j < (dp[v].size()); j++) {
        ndp[i + j] = max(ndp[i + j], dp[u][i] + dp[v][j]);
        ndp[i + j + 1] = max(ndp[i + j + 1], dp[u][i] + dp[v][j].div());
      }
    }
    dp[u] = ndp;
  }
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n;
    int m;
    cin >> n >> m;
    vector<vector<node> > dp(n, vector<node>(1, node()));
    vector<vector<int> > edge(n, vector<int>());
    for (int i = (0); i < (n); i++) {
      int x;
      cin >> x;
      dp[i][0].dt -= x;
    }
    for (int i = (0); i < (n); i++) {
      int x;
      cin >> x;
      dp[i][0].dt += x;
    }
    for (int i = (1); i < (n); i++) {
      int u, v;
      cin >> u >> v, u--, v--;
      edge[u].push_back(v), edge[v].push_back(u);
    }
    dfs(0, 0, edge, dp);
    cout << (dp[0][m - 1].div()).win << endl;
  }
  return 0;
}
