#include <bits/stdc++.h>
using namespace std;
inline int readint() {
  int a = 0;
  char c = getchar(), f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -f;
  for (; '0' <= c && c <= '9'; c = getchar())
    a = (a << 3) + (a << 1) + (c ^ 48);
  return a * f;
}
const int MaxN = 1005;
const int MaxM = 2005;
struct Edge {
  int to, nxt;
  Edge() { to = nxt = 0; }
  Edge(int T, int N) { to = T, nxt = N; }
};
Edge e[MaxM << 1];
int head[MaxN], cntEdge;
void addEdge(int a, int b) {
  e[cntEdge] = Edge(b, head[a]);
  head[a] = cntEdge++;
}
const int infty = (1 << 30) - 1;
int a[MaxN], b[MaxN];
bool vis[MaxN], cur[MaxN];
int pre[MaxN];
int getPath(int x) {
  if (vis[x]) return 0;
  vis[x] = true;
  return min(infty, getPath(pre[x]) + b[x]);
}
int dfs(int now, int x) {
  cur[x] = true;
  now = min(now + b[x], infty);
  for (int i = head[x]; ~i; i = e[i].nxt) {
    if (e[i].to == pre[x]) continue;
    if (now <= a[e[i].to]) continue;
    if (cur[e[i].to]) return getPath(x) + getPath(e[i].to);
    pre[e[i].to] = x;
    int f = dfs(now, e[i].to);
    if (~f) return f;
  }
  return -1;
}
int n;
bool check(int now) {
  memset(vis + 1, 0, n);
  memset(pre + 1, 0, n << 2);
  for (vis[1] = 1; true;) {
    memcpy(cur + 1, vis + 1, n);
    bool ok = 1;
    int f = -1;
    for (int i = (1); i <= (n); ++i) ok = ok && vis[i];
    if (ok) return true;
    for (int i = 1; i <= n; ++i) {
      if (!vis[i]) continue;
      for (int j = head[i]; ~j; j = e[j].nxt)
        if (!vis[e[j].to])
          if (now > a[e[j].to]) {
            pre[e[j].to] = i;
            f = dfs(now, e[j].to);
            if (~f) {
              now += f;
              break;
            }
          }
      if (~f) break;
    }
    if (f == -1) return false;
    now = min(now, infty);
  }
  return false;
}
int main() {
  for (int T = readint(); T; --T) {
    n = readint();
    int m = readint();
    cntEdge = 0;
    memset(head + 1, -1, n << 2);
    for (int i = (2); i <= (n); ++i) a[i] = readint();
    for (int i = (2); i <= (n); ++i) b[i] = readint();
    for (int i = 1, x, y; i <= m; ++i) {
      x = readint(), y = readint();
      addEdge(x, y), addEdge(y, x);
    }
    int L = 0, R = 1e9 + 1, mid = R >> 1;
    for (; L != R; mid = (L + R) >> 1)
      if (check(mid))
        R = mid;
      else
        L = mid + 1;
    printf("%d\n", L);
  }
  return 0;
}
