#include <bits/stdc++.h>
using namespace std;
inline void minimize(int &x, int y) { x = min(x, y); }
inline void maximize(int &x, int y) { x = max(x, y); }
const int N = 4067, base = 1e9 + 7;
int n, m, t;
long long res;
vector<int> to[N];
int a[N], con[N];
struct Node {
  long long g, p;
  Node() {}
  Node(int g1, int p1) {
    g = g1;
    p = p1;
  }
} f[N][N], nf[N][N];
bool comp(Node c1, Node c2) {
  if (c1.g < c2.g) return true;
  if (c1.g == c2.g && c1.p < c2.p) return true;
  return false;
}
void dfs(int x, int t) {
  con[x] = 1;
  f[x][1].g = 0;
  f[x][1].p = a[x];
  for (auto y : to[x])
    if (y != t) {
      dfs(y, x);
      for (int i = 1; i <= con[x] + con[y]; i++) nf[x][i] = Node(-1, -1);
      for (int i = 1; i <= con[x]; i++)
        for (int j = 1; j <= con[y]; j++) {
          Node nn = Node(f[x][i].g + f[y][j].g, f[x][i].p + f[y][j].p);
          if (comp(nf[x][i + j - 1], nn)) {
            nf[x][i + j - 1] = nn;
          }
          nn = Node(f[x][i].g + f[y][j].g + (f[y][j].p > 0), f[x][i].p);
          if (comp(nf[x][i + j], nn)) {
            nf[x][i + j] = nn;
          }
        }
      for (int i = 1; i <= con[x] + con[y]; i++) f[x][i] = nf[x][i];
      con[x] += con[y];
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  for (int test = 1; test <= t; test++) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      a[i] = x - a[i];
    }
    for (int i = 1; i <= n; i++) to[i].clear();
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) f[i][j] = Node(-1, -1);
    for (int i = 1; i <= n - 1; i++) {
      int x, y, w;
      cin >> x >> y;
      to[x].push_back(y);
      to[y].push_back(x);
    }
    dfs(1, 0);
    cout << f[1][m].g + (f[1][m].p > 0) << endl;
  }
  return 0;
}
