#include <bits/stdc++.h>
using namespace std;

#define lint long long
#define inf 0x3f3f3f3f3f3f3f3f

const int N = 3005;

vector<int> g[N];

int n, m, sz[N];
int a[N], b[N];
struct T { int a; lint b; } dp[N][N], e[N], tmp;
T operator + (T a, T b) { return { a.a + b.a, a.b + b.b }; }
bool operator < (T a, T b) { return a.a == b.a ? a.b < b.b : a.a < b.a; }

void dfs (int u, int from) {
	sz[u] = 1;
	dp[u][1] = { 0, a[u] - b[u] };
	for (int & v : g[u]) if (v != from) {
		dfs(v, u);
		for (int i = 1; i < N; i++)
			e[i] = { 0, - inf };
		for (int i = 1; i <= sz[u]; i++) {
			for (int j = 1; j <= sz[v] && i + j <= m; j++) {
				T & x = dp[u][i];
				T & y = dp[v][j];
				e[i + j] = max(e[i + j], { x.a + y.a + (y.b > 0), x.b });
				e[i + j - 1] = max(e[i + j - 1], { x.a + y.a, x.b + y.b });
			}
		}
		sz[u] += sz[v];
		for (int i = 1; i < N; i++)
			dp[u][i] = e[i];
	}
}

int main (void) {
	int kase;
	scanf("%d", &kase);
	while (kase--) {
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; i++)
			g[i].clear();
		for (int i = 1; i <= n; i++)
			scanf("%d", a + i);
		for (int i = 1; i <= n; i++)
			scanf("%d", b + i);
		for (int i = 1, u, v; i < n; i++) {	
			scanf("%d%d", &u, &v);
			g[u].push_back(v);
			g[v].push_back(u);
		}
		dfs(1, 1);

		int ans = 0;
		for (int i = 1; i <= n; i++)
			ans = max(ans, dp[1][i].a + (dp[1][i].b > 0));
		printf("%d\n", ans);
	}
}