#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e3 + 5;
struct Group {
  int a, b;
  Group(int a, int b) : a(a), b(b) {}
  Group operator+(const Group &B) const { return Group(a + B.a, b + B.b); }
  bool operator<(const Group &B) const {
    if (a != B.a)
      return a < B.a;
    else
      return b < B.b;
  }
  Group settle() { return Group(a + (b > 0), 0); }
};
vector<vector<Group> > g;
vector<int> Edge[MAXN];
void Merge(vector<Group> &ga, vector<Group> &gb) {
  vector<Group> res;
  res.assign(ga.size() + gb.size(), Group(-1, 0));
  for (int i = 0; i < ga.size(); i++)
    for (int j = 0; j < gb.size(); j++) {
      res[i + j] = max(res[i + j], ga[i] + gb[j]);
      res[i + j + 1] = max(res[i + j + 1], ga[i] + gb[j].settle());
    }
  ga = res;
}
void Dfs(int s, int f) {
  for (auto e : Edge[s])
    if (e != f) {
      Dfs(e, s);
      Merge(g[s], g[e]);
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, m, v;
    cin >> n >> m;
    g.assign(n + 1, vector<Group>(1, Group(0, 0)));
    for (int i = 1; i <= n; i++) Edge[i].clear();
    for (int i = 1; i <= n; i++) {
      cin >> v;
      g[i][0].b -= v;
    }
    for (int i = 1; i <= n; i++) {
      cin >> v;
      g[i][0].b += v;
    }
    int s, e;
    for (int i = 1; i < n; i++) {
      cin >> s >> e;
      Edge[s].push_back(e);
      Edge[e].push_back(s);
    }
    Dfs(1, 0);
    cout << g[1][m - 1].settle().a << '\n';
  }
}
