#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
} read;

const int maxn = 3030;
const ll inf = 1000000000000000000;
std::vector<int> G[maxn];
int a[maxn];
struct DP {
	ll x, y;
} f[maxn][maxn][3], g[maxn][3];
int size[maxn];

inline void chkmax (DP &f1, DP f2) {
	if(f2.x > f1.x or (f2.x == f1.x and f2.y > f1.y))
		f1 = f2;
}

DP merge (DP f1, DP f2) {
	return {f1.x + f2.x, f1.y + f2.y};
}

DP add (DP f1, DP f2) {
	return {f1.x + f2.x + (f2.y > 0), f1.y};
}

void dp (int u, int fa) {
	int &n = size[u] = 1;
	f[u][1][0] = f[u][1][1] = f[u][1][2] = {0, a[u]};

	for(int v : G[u])
		if(v != fa)
			dp(v, u);

	for(int v : G[u])
		if(v != fa) {
			int m = size[v];
			for(int i = 1; i <= n + m; i ++)
				g[i][0] = g[i][1] = g[i][2] = {0, -inf};
			for(int i = 1; i <= n; i ++)
				for(int j = 1; j <= m; j ++) {
					chkmax(g[i + j - 1][2], merge(f[u][i][1], f[v][j][1]));
					chkmax(g[i + j - 1][1], merge(f[u][i][0], f[v][j][1]));
					chkmax(g[i + j][0], add(f[u][i][0], f[v][j][2]));
					chkmax(g[i + j][1], add(f[u][i][1], f[v][j][2]));
					chkmax(g[i + j][2], add(f[u][i][2], f[v][j][2]));

				}
			n += m;
			for(int i = 1; i <= n; i ++)
				for(int o = 0; o < 3; o ++)
					f[u][i][o] = g[i][o];
		}
}

int main () {
	int T = read;
	while(T --) {
		int n = read, m = read;
		for(int i = 1; i <= n; i ++)
			a[i] = -read;
		for(int i = 1; i <= n; i ++)
			a[i] += read;
		for(int i = 1; i <= n; i ++)
			G[i].clear();
		for(int i = 1; i < n; i ++) {
			int u = read, v = read;
			G[u].push_back(v);
			G[v].push_back(u);
		}
		dp(1, 0);
		printf("%lld\n", f[1][m][2].x + (f[1][m][2].y > 0));
	}
}
