#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif

#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
template<class T> int sz(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;

vector<int> b, w;
vector<vector<int>> adj;
vector<vector<pair<int, LL>>> dp;
int ans = 0, t;

void dfs(int v = 0, int p = -1) {
	int sz = 1;
	for(int u : adj[v]) {
		if(u != p) {
			dfs(u, v);
			b[v] += b[u];
			sz += dp[u].size() - 1;
		}
	}

	dp[v].resize(sz + 1);
	dp[v][0] = {0, b[v]};
	int q = 0;
	for(int u : adj[v]) {
		for(int i = sz; i >= 0; i--) {
			for(int j = max(0, i - size(dp[u]) + 1); j <= q; j++) {
				auto m = dp[v][j];
				m.ST += dp[u][i - j].ST;
				m.ND += dp[u][i - j].ND - b[u];
				dp[v][i] = max(dp[v][i], m);
				m.ST += (m.ND > 0), m.ND = 0;
				dp[v][i + 1] = max(dp[v][i + 1], m);
				if(v == 0 && i + 1 == t) ans = max(ans, m.ST);
			}
		}
	}

	debug(v, dp[v]);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int T;
	cin >> T;
	REP(it, T) {
		int n, m;
		cin >> n >> t;
		auto re = [&](auto &vec) {
			vec.clear();
			vec.resize(n);
		};

		re(b), re(w);
		REP(i, n) cin >> b[i];
		REP(i, n) {
			cin >> w[i];
			b[i] = w[i] - b[i];
		}

		re(adj), re(dp);
		REP(i, n - 1) {
			int a, b;
			cin >> a >> b;
			adj[a - 1].emplace_back(b - 1);
			adj[b - 1].emplace_back(a - 1);
		}

		ans = 0;
		dfs();

		cout << ans << "\n";
	}
}
