#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
pair<int, int> edge[100009];
int a[100009], b[100009], arr[100009], ata[100009], n, m;
long long cost[100009];
int tap(int x) {
  if (ata[x] == x) return x;
  return ata[x] = tap(ata[x]);
}
void merge(int x, int y) {
  x = tap(x);
  y = tap(y);
  cost[x] += cost[y];
  ata[y] = x;
}
long long get(int x, int y) {
  if (tap(x) == tap(y)) return 0;
  return cost[tap(x)] + cost[tap(y)];
}
int ok() {
  for (int i = 1; i <= n; i++) ata[i] = i, cost[i] = arr[i];
  for (int i = 0; i < n - m; i++) {
    long long mx = -long long(1e15);
    int who = -1;
    for (int j = 0; j < n - 1; j++)
      if (umax(mx, get(edge[j].first, edge[j].second))) who = j;
    if (~who)
      merge(edge[who].first, edge[who].second);
    else
      assert(0);
  }
  int res = 0;
  for (int i = 1; i <= n; i++)
    if (ata[i] == i) res += (cost[i] > 0);
  return res;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    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; i <= n; i++) arr[i] = b[i] - a[i];
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      edge[i] = make_pair(u, v);
    }
    printf("%d\n", ok());
  }
  return 0;
}
