#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int n, m, x, y, t, b[N], w[N], sub[N];
vector<int> g[N];
pair<long long, long long> dp[N][N], e;
pair<long long, long long> max_m(pair<long long, long long> p1,
                                 pair<long long, long long> p2,
                                 pair<long long, long long> p3) {
  p2.first += p3.first, p2.second += p3.second;
  if (p1.first > p2.first || (p1.first == p2.first && p1.second > p2.second))
    return p1;
  return p2;
}
void dfs(int x, int par) {
  for (int i = 1; i < m + 1; i++) dp[x][i].second = dp[x][i].first = -1e18;
  sub[x] = 1;
  for (int i = 0; i < g[x].size(); i++)
    if (g[x][i] != par) {
      dfs(g[x][i], x);
      sub[x] += sub[g[x][i]];
      for (int j = min(sub[x], m); j >= 0; j--) {
        dp[x][j].first += dp[g[x][i]][0].first,
            dp[x][j].second += dp[g[x][i]][0].second;
        for (int k = min(sub[x] - sub[g[x][i]], j - 1);
             k >= j - sub[g[x][i]] && k >= 0; k--)
          dp[x][j] = max_m(dp[x][j], dp[x][k], dp[g[x][i]][j - k]);
      }
    }
  for (int i = 0; i < min(sub[x], m) + 1; i++) dp[x][i].second += w[x];
  pair<long long, long long> p;
  if (x != 1) {
    for (int i = min(sub[x], m); i >= 1; i--) {
      p.first = dp[x][i - 1].first, p.second = 0;
      p.first += (dp[x][i - 1].second > 0);
      dp[x][i] = max_m(dp[x][i], p, e);
    }
  } else {
    for (int i = min(sub[x], m); i >= 1; i--) {
      p.first = dp[x][i - 1].first, p.second = 0;
      p.first += (dp[x][i - 1].second > 0);
      dp[x][i] = p;
    }
  }
}
void clear() {
  for (int i = 1; i < n + 1; i++) g[i].clear();
  for (int i = 1; i < n + 1; i++)
    for (int j = 0; j < min(m, sub[i]) + 1; j++)
      dp[i][j].first = dp[i][j].second = 0;
}
int main() {
  cin >> t;
  while (t--) {
    clear();
    scanf("%d%d", &n, &m);
    ;
    for (int i = 0; i < n; i++) scanf("%d", &b[i + 1]);
    ;
    for (int i = 0; i < n; i++) {
      scanf("%d", &w[i + 1]);
      ;
      w[i + 1] -= b[i + 1];
    }
    for (int i = 1; i < n; i++) {
      scanf("%d%d", &x, &y);
      ;
      g[x].push_back(y);
      g[y].push_back(x);
    }
    dfs(1, 0);
    cout << dp[1][m].first << endl;
  }
}
