#include <bits/stdc++.h>
using namespace std;
long long mod(long long a) {
  long long c = a % (long long)(1E9 + 7);
  if (c >= 0) return c;
  return c + (long long)(1E9 + 7);
}
long long inf = (long long)1E16;
long long max(long long a, long long b) {
  if (a < b)
    return b;
  else
    return a;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
void Max(long long &pos, long long val) { pos = max(pos, val); }
void Min(long long &pos, long long val) { pos = min(pos, val); }
long double EPS = 1E-9;
void Max(pair<long long, long long> &pos, pair<long long, long long> val) {
  pos = max(pos, val);
}
void print(pair<long long, long long> a) {
  cout << a.first << "¥" << a.second << " ";
}
bool anspro() {
  long long n, m;
  cin >> n >> m;
  long long a[n + 1], b[n + 1];
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) cin >> b[i];
  for (long long i = 1; i <= n; i++) a[i] = b[i] - a[i];
  vector<long long> vec[n + 1];
  for (long long i = 1; i <= n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    vec[x].push_back(y);
    vec[y].push_back(x);
  }
  long long par[n + 1];
  memset(par, -1, sizeof(par));
  par[1] = 0;
  vector<long long> chi[n + 1];
  queue<long long> q;
  q.push(1);
  vector<long long> v;
  while (!q.empty()) {
    long long t = q.front();
    q.pop();
    v.push_back(t);
    for (auto x : vec[t]) {
      if (par[x] == -1) {
        par[x] = t;
        q.push(x);
        chi[t].push_back(x);
      }
    }
  }
  reverse(v.begin(), v.end());
  long long sz[n + 1];
  for (auto x : v) {
    sz[x] = 1;
    for (auto y : chi[x]) {
      sz[x] += sz[y];
    }
  }
  pair<long long, long long> dp[n + 1][n + 1];
  for (long long i = 0; i <= n; i++)
    for (long long j = 0; j <= n; j++)
      dp[i][j] = pair<long long, long long>(-inf, -inf);
  for (auto t : v) {
    if (chi[t].size() == 0) {
      dp[t][0] = pair<long long, long long>(0, a[t]);
      continue;
    }
    long long cs = chi[t].size();
    pair<long long, long long> ep[2][sz[t] + 1];
    for (long long i = 0; i <= 1; i++)
      for (long long j = 0; j <= sz[t]; j++)
        ep[i][j] = pair<long long, long long>(-inf, -inf);
    ep[0][0] = pair<long long, long long>(0, a[t]);
    for (long long i = 0; i <= cs - 1; i++) {
      for (long long j = 0; j <= sz[t]; j++) {
        if (ep[i & 1][j].first <= -inf / 2) break;
        long long pos = chi[t][i];
        for (long long k = 0; k <= sz[pos] - 1; k++) {
          if (j + k <= sz[t]) {
            Max(ep[(i + 1) & 1][j + k],
                pair<long long, long long>(
                    ep[i & 1][j].first + dp[pos][k].first,
                    ep[i & 1][j].second + dp[pos][k].second));
          }
          if (j + k + 1 <= sz[t]) {
            long long c = 0;
            if (dp[pos][k].second > 0) c++;
            Max(ep[(i + 1) & 1][j + k + 1],
                pair<long long, long long>(
                    ep[i & 1][j].first + dp[pos][k].first + c,
                    ep[i & 1][j].second));
          }
        }
      }
      for (long long j = 0; j <= sz[t]; j++)
        ep[i & 1][j] = pair<long long, long long>(-inf, -inf);
    }
    for (long long j = 0; j <= sz[t]; j++) {
      dp[t][j] = ep[cs & 1][j];
    }
  }
  long long ans = dp[1][m - 1].first;
  if (dp[1][m - 1].second > 0) ans++;
  cout << ans << endl;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    anspro();
  }
  return 0;
}
