#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) res += ", ";
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
class DSU {
 public:
  DSU(int n, const vector<int> &a) : num_comp_(n), root_(n + 1, 0) {
    ls_.resize(n + 1);
    a_.resize(n + 1);
    for (int i = 1; i <= n; i++) {
      ls_[i].push_back(i);
      a_[i] = a[i];
    }
  }
  int num_comp() { return num_comp_; }
  long long a(int u) { return a_[u]; }
  vector<int> &ls(int u) { return ls_[u]; }
  int GetRoot(int u) { return root_[u] ? root_[u] = GetRoot(root_[u]) : u; }
  bool Unite(int u, int v) {
    u = GetRoot(u);
    v = GetRoot(v);
    if (u == v) return 0;
    a_[v] += a_[u];
    if (ls_[v].size() < ls_[u].size()) {
      swap(ls_[u], ls_[v]);
    }
    ls_[v].insert(ls_[v].end(), ls_[u].begin(), ls_[u].end());
    ls_[u].clear();
    root_[u] = v;
    num_comp_--;
    return 1;
  }

 private:
  int num_comp_;
  vector<long long> a_;
  vector<int> root_;
  vector<vector<int>> ls_;
};
void Solve(int test) {
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0);
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> b(n + 1, 0);
  for (int i = 2; i <= n; i++) {
    cin >> b[i];
  }
  vector<vector<pair<int, int>>> adj(n + 1, vector<pair<int, int>>());
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back({v, i});
    adj[v].push_back({u, i});
  }
  auto Check = [&](int init_value) -> bool {
    b[1] = init_value;
    DSU dsu(n, b);
    while (dsu.num_comp() > 1) {
      queue<int> q;
      vector<int> d(n + 1, -1);
      vector<int> last_edge(n + 1, -1);
      vector<int> last_ver(n + 1, -1);
      vector<long long> cur(n + 1, 0);
      auto root = dsu.GetRoot(1);
      cur[root] = dsu.a(root);
      d[root] = 0;
      q.push(root);
      bool found_loop = false;
      pair<int, int> loop;
      while (!q.empty() && !found_loop) {
        int u = q.front();
        q.pop();
        for (int node_u : dsu.ls(u)) {
          for (auto [node_v, edge_id] : adj[node_u]) {
            auto v = dsu.GetRoot(node_v);
            if (u == v) continue;
            if (last_edge[u] == edge_id) continue;
            if (cur[u] <= a[node_v]) continue;
            if (d[v] == -1) {
              d[v] = d[u] + 1;
              last_edge[v] = edge_id;
              last_ver[v] = u;
              cur[v] = cur[u] + dsu.a(v);
              q.push(v);
            } else {
              found_loop = true;
              loop = {u, v};
              break;
            }
          }
          if (found_loop) {
            break;
          }
        }
      }
      if (!found_loop) {
        break;
      }
      auto [u, v] = loop;
      auto Go = [&](int u) {
        while (u != -1) {
          dsu.Unite(u, root);
          u = last_ver[u];
        }
      };
      Go(u);
      Go(v);
    }
    return dsu.num_comp() == 1;
  };
  int low = 0, high = *max_element(a.begin(), a.end()) + 1;
  while (high - low > 1) {
    int mid = low + high >> 1;
    if (Check(mid)) {
      high = mid;
    } else {
      low = mid;
    }
  }
  cout << high << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tc;
  cin >> tc;
  for (int test = 1; test <= tc; ++test) Solve(test);
  return 0;
}

### Prompt

Generate a CPP solution to the following problem:

In a certain video game, the player controls a hero characterized by a single integer value: power.

On the current level, the hero got into a system of n caves numbered from 1 to n, and m tunnels between them. Each tunnel connects two distinct caves. Any two caves are connected with at most one tunnel. Any cave can be reached from any other cave by moving via tunnels.

The hero starts the level in cave 1, and every other cave contains a monster.

The hero can move between caves via tunnels. If the hero leaves a cave and enters a tunnel, he must finish his movement and arrive at the opposite end of the tunnel.

The hero can use each tunnel to move in both directions. However, the hero can not use the same tunnel twice in a row. Formally, if the hero has just moved from cave i to cave j via a tunnel, he can not head back to cave i immediately after, but he can head to any other cave connected to cave j with a tunnel.

It is known that at least two tunnels come out of every cave, thus, the hero will never find himself in a dead end even considering the above requirement.

To pass the level, the hero must beat the monsters in all the caves. When the hero enters a cave for the first time, he will have to fight the monster in it. The hero can beat the monster in cave i if and only if the hero's power is strictly greater than a_i. In case of beating the monster, the hero's power increases by b_i. If the hero can't beat the monster he's fighting, the game ends and the player loses.

After the hero beats the monster in cave i, all subsequent visits to cave i won't have any consequences: the cave won't have any monsters, and the hero's power won't change either.

Find the smallest possible power the hero must start the level with to be able to beat all the monsters and pass the level.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 100). Description of the test cases follows.

The first line of each test case contains two integers n and m (3 ≤ n ≤ 1000; n ≤ m ≤ min((n(n-1))/(2), 2000)) — the number of caves and tunnels.

The second line contains n-1 integers a_2, a_3, …, a_n (1 ≤ a_i ≤ 10^9) — values the hero's power are compared to while fighting monsters in caves 2, 3, …, n.

The third line contains n-1 integers b_2, b_3, …, b_n (1 ≤ b_i ≤ 10^9) — increases applied to the hero's power for beating monsters in caves 2, 3, …, n.

Each of the next m lines contains two integers u_i and v_i (1 ≤ u_i, v_i ≤ n; u_i ≠ v_i) — the numbers of caves connected with a tunnel.

No two caves are connected with more than one tunnel. Any cave can be reached from any other cave by moving via tunnels. At least two tunnels come out of every cave.

It is guaranteed that the sum of n over all test cases does not exceed 1000, and the sum of m over all test cases does not exceed 2000.

Output

For each test case print a single integer — the smallest possible power the hero must start the level with to be able to beat all the monsters and pass the level.

Example

Input


3
4 4
11 22 13
8 7 5
1 2
2 3
3 4
4 1
4 4
11 22 13
5 7 8
1 2
2 3
3 4
4 1
5 7
10 40 20 30
7 2 10 5
1 2
1 5
2 3
2 4
2 5
3 4
4 5


Output


15
15
19

Note

In the first test case, the hero can pass the level with initial power 15 as follows: 

  * move from cave 1 to cave 2: since 15 > 11, the hero beats the monster, and his power increases to 15 + 8 = 23; 
  * move from cave 2 to cave 3: since 23 > 22, the hero beats the monster, and his power increases to 23 + 7 = 30; 
  * move from cave 3 to cave 4: since 30 > 13, the hero beats the monster, and his power increases to 30 + 5 = 35. 



In the second test case, the situation is similar except that the power increases for beating monsters in caves 2 and 4 are exchanged. The hero can follow a different route, 1 → 4 → 3 → 2, and pass the level with initial power 15.

In the third test case, the hero can pass the level with initial power 19 as follows: 

  * move from cave 1 to cave 2: since 19 > 10, the hero beats the monster, and his power increases to 19 + 7 = 26; 
  * move from cave 2 to cave 4: since 26 > 20, the hero beats the monster, and his power increases to 26 + 10 = 36; 
  * move from cave 4 to cave 5: since 36 > 30, the hero beats the monster, and his power increases to 36 + 5 = 41; 
  * move from cave 5 to cave 2: there is no monster in this cave anymore, nothing happens; 
  * move from cave 2 to cave 3: since 41 > 40, the hero beats the monster, and his power increases to 41 + 2 = 43. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) res += ", ";
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
class DSU {
 public:
  DSU(int n, const vector<int> &a) : num_comp_(n), root_(n + 1, 0) {
    ls_.resize(n + 1);
    a_.resize(n + 1);
    for (int i = 1; i <= n; i++) {
      ls_[i].push_back(i);
      a_[i] = a[i];
    }
  }
  int num_comp() { return num_comp_; }
  long long a(int u) { return a_[u]; }
  vector<int> &ls(int u) { return ls_[u]; }
  int GetRoot(int u) { return root_[u] ? root_[u] = GetRoot(root_[u]) : u; }
  bool Unite(int u, int v) {
    u = GetRoot(u);
    v = GetRoot(v);
    if (u == v) return 0;
    a_[v] += a_[u];
    if (ls_[v].size() < ls_[u].size()) {
      swap(ls_[u], ls_[v]);
    }
    ls_[v].insert(ls_[v].end(), ls_[u].begin(), ls_[u].end());
    ls_[u].clear();
    root_[u] = v;
    num_comp_--;
    return 1;
  }

 private:
  int num_comp_;
  vector<long long> a_;
  vector<int> root_;
  vector<vector<int>> ls_;
};
void Solve(int test) {
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0);
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> b(n + 1, 0);
  for (int i = 2; i <= n; i++) {
    cin >> b[i];
  }
  vector<vector<pair<int, int>>> adj(n + 1, vector<pair<int, int>>());
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back({v, i});
    adj[v].push_back({u, i});
  }
  auto Check = [&](int init_value) -> bool {
    b[1] = init_value;
    DSU dsu(n, b);
    while (dsu.num_comp() > 1) {
      queue<int> q;
      vector<int> d(n + 1, -1);
      vector<int> last_edge(n + 1, -1);
      vector<int> last_ver(n + 1, -1);
      vector<long long> cur(n + 1, 0);
      auto root = dsu.GetRoot(1);
      cur[root] = dsu.a(root);
      d[root] = 0;
      q.push(root);
      bool found_loop = false;
      pair<int, int> loop;
      while (!q.empty() && !found_loop) {
        int u = q.front();
        q.pop();
        for (int node_u : dsu.ls(u)) {
          for (auto [node_v, edge_id] : adj[node_u]) {
            auto v = dsu.GetRoot(node_v);
            if (u == v) continue;
            if (last_edge[u] == edge_id) continue;
            if (cur[u] <= a[node_v]) continue;
            if (d[v] == -1) {
              d[v] = d[u] + 1;
              last_edge[v] = edge_id;
              last_ver[v] = u;
              cur[v] = cur[u] + dsu.a(v);
              q.push(v);
            } else {
              found_loop = true;
              loop = {u, v};
              break;
            }
          }
          if (found_loop) {
            break;
          }
        }
      }
      if (!found_loop) {
        break;
      }
      auto [u, v] = loop;
      auto Go = [&](int u) {
        while (u != -1) {
          dsu.Unite(u, root);
          u = last_ver[u];
        }
      };
      Go(u);
      Go(v);
    }
    return dsu.num_comp() == 1;
  };
  int low = 0, high = *max_element(a.begin(), a.end()) + 1;
  while (high - low > 1) {
    int mid = low + high >> 1;
    if (Check(mid)) {
      high = mid;
    } else {
      low = mid;
    }
  }
  cout << high << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tc;
  cin >> tc;
  for (int test = 1; test <= tc; ++test) Solve(test);
  return 0;
}

```