#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const long long INF = (1LL << 62) - 1;
const int MAXN = 100010;
int t, n, m;
int V[3010], sz[3010];
long long dp[3010][3010][2];
vector<int> G[3010];
void Update(long long a, long long b, long long &c, long long &d) {
  if (a > c)
    c = a, d = b;
  else if (a == c)
    d = max(d, b);
}
void Dfs(int p, int pre) {
  sz[p] = 1;
  long long tmp[3010][2];
  for (int i = 0; i <= n; ++i) tmp[i][0] = tmp[i][1] = -1;
  dp[p][0][0] = 0, dp[p][0][1] = V[p];
  for (int i = 0; i <= ((int)(G[p]).size()) - 1; ++i) {
    int v = G[p][i];
    if (v == pre) continue;
    Dfs(v, p);
    for (int q = 0; q <= sz[v]; ++q)
      if (dp[v][q][0] != -1) {
        for (int j = 0; j <= sz[p]; ++j)
          if (dp[p][j][0] != -1) {
            Update(dp[v][q][0] + dp[p][j][0], dp[v][q][1] + dp[p][j][1],
                   tmp[q + j][0], tmp[q + j][1]);
          }
      }
    sz[p] += sz[v];
    for (int j = 0; j <= sz[p]; ++j) {
      dp[p][j][0] = tmp[j][0], dp[p][j][1] = tmp[j][1];
      tmp[j][0] = tmp[j][1] = -1;
    }
  }
  for (int j = sz[p] - 1; j >= 0; --j) {
    Update(dp[p][j][0] + (dp[p][j][1] > 0), 0, dp[p][j + 1][0],
           dp[p][j + 1][1]);
  }
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i <= n; ++i)
      for (int j = 0; j <= n; ++j) dp[i][j][0] = dp[i][j][1] = -1;
    for (int i = 1; i <= n; ++i) {
      int a;
      cin >> a;
      V[i] = -a;
      G[i].clear();
    }
    for (int i = 1; i <= n; ++i) {
      int a;
      cin >> a;
      V[i] += a;
    }
    for (int i = 1; i <= n - 1; ++i) {
      int a, b;
      cin >> a >> b;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    Dfs(1, 0);
    cout << dp[1][m - 1][0] + (dp[1][m - 1][1] > 0) << endl;
  }
  return 0;
}
