#include <bits/stdc++.h>
using namespace std;
const int MN = 3005, inf = 1000000005, mod = 1000000007;
const long long INF = 1000000000000000005LL;
pair<int, long long> dp[MN][MN], tmp[MN];
vector<int> G[MN];
int W[MN], pod[MN];
void dfs(int x) {
  pod[x] = 1;
  dp[x][1] = {0, (long long)W[x]};
  for (auto v : G[x])
    if (!pod[v]) {
      dfs(v);
      pod[x] += pod[v];
      for (int j = 1; j <= pod[x]; ++j) tmp[j] = {0, -INF};
      for (int j = 1; j <= pod[x] - pod[v]; ++j) {
        for (int k = 1; k <= pod[v]; ++k) {
          pair<int, long long> a, b = {-1, -1};
          a = {dp[x][j].first + dp[v][k].first, dp[x][j].second};
          b = {dp[x][j].first + dp[v][k].first - (dp[v][k].second > 0LL),
               dp[x][j].second + dp[v][k].second};
          tmp[j + k] = max(tmp[j + k], a);
          tmp[j + k - 1] = max(tmp[j + k - 1], b);
        }
      }
      for (int j = 1; j <= pod[x]; ++j) dp[x][j] = tmp[j];
    }
  for (int i = 1; i <= pod[x]; ++i) {
    dp[x][i].first += (dp[x][i].second > 0LL);
  }
}
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &W[i]);
  for (int i = 1; i <= n; ++i) {
    int w;
    scanf("%d", &w);
    W[i] = w - W[i];
  }
  for (int i = 1; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(1);
  printf("%d\n", dp[1][m].first);
  for (int i = 1; i <= n; ++i) {
    G[i].clear();
    pod[i] = W[i] = 0;
    tmp[i] = {0, 0};
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
