#include <bits/stdc++.h>
using namespace std;
namespace io {
const int SI = 1 << 21 | 1;
char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
int f, t;
inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; }
inline void pc(char x) {
  *OS++ = x;
  if (OS == OT) flush();
}
template <class I>
inline void rd(I &x) {
  for (f = 1, c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                              IS == IT ? EOF : *IS++)
                            : *IS++);
       c < '0' || c > '9';
       c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++))
    if (c == '-') f = -1;
  for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15),
      c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                      IS == IT ? EOF : *IS++)
                    : *IS++))
    ;
  x *= f;
}
inline void rds(char *s, int &x) {
  for (c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++);
       c < 33 || c > 126;
       c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++))
    ;
  for (x = 0; c >= 33 && c <= 126;
       s[++x] = c, c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                                   IS == IT ? EOF : *IS++)
                                 : *IS++))
    ;
  s[x + 1] = '\0';
}
template <class I>
inline void print(I x, char k = '\n') {
  if (!x) pc('0');
  if (x < 0) pc('-'), x = -x;
  while (x) ch[++t] = x % 10 + '0', x /= 10;
  while (t) pc(ch[t--]);
  pc(k);
}
inline void prints(string s) {
  int x = s.length();
  while (t < x) pc(s[t++]);
  pc('\n'), t = 0;
}
struct Flush {
  ~Flush() { flush(); }
} flusher;
}  // namespace io
using io::print;
using io::prints;
using io::rd;
using io::rds;
const int N = 3e3 + 7;
int n, m, s[N];
long long a[N];
pair<int, long long> f[N][N], g[N][N];
vector<int> e[N];
void dfs(int x, int fa) {
  s[x] = 1, f[x][1] = make_pair(0, a[x]);
  for (unsigned int i = 0; i < e[x].size(); i++) {
    int y = e[x][i];
    if (y == fa) continue;
    dfs(y, x);
    for (int j = 1; j <= s[x] + s[y]; j++) g[x][j] = make_pair(0, -1e18);
    for (int j = 1; j <= s[x]; j++)
      for (int k = 1; k <= s[y]; k++) {
        g[x][j + k] = max(g[x][j + k], make_pair(f[x][j].first + f[y][k].first +
                                                     (f[y][k].second > 0),
                                                 f[x][j].second));
        g[x][j + k - 1] =
            max(g[x][j + k - 1], make_pair(f[x][j].first + f[y][k].first,
                                           f[x][j].second + f[y][k].second));
      }
    s[x] += s[y];
    for (int j = 1; j <= s[x]; j++) f[x][j] = g[x][j];
  }
}
inline void solve() {
  rd(n), rd(m);
  for (int i = 1; i <= n; i++) rd(a[i]), e[i].clear();
  for (int i = 1, x; i <= n; i++) rd(x), a[i] = x - a[i];
  for (int i = 1, x, y; i < n; i++)
    rd(x), rd(y), e[x].push_back(y), e[y].push_back(x);
  dfs(1, 0), print(f[1][m].first + (f[1][m].second > 0));
}
int main() {
  int T;
  rd(T);
  while (T--) solve();
  return 0;
}
