> File Name: 5852.cpp
> Author: jiangyuzhu
> Mail: 834138558@qq.com
> Created Time: 2016/10/9 23:31:42
************************************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#include<iostream>
#include<cstdio>
#include<cmath>
typedef long long ll;
using namespace std;
const int maxn = 1e2 + 5, maxm = 1e5 + 5, mod = 1e9 + 7;
ll a[maxn][maxn];
int sign;
int N;
ll solve()
{
ll ans = 1;
for(int i = 0; i < N; i++){
for(int j = i + 1; j < N; j++){
int x = i, y = j;
while(a[y][i]){
ll t = a[x][i] / a[y][i];
for(int k = i; k < N; k++)
a[x][k] = (a[x][k] - a[y][k] * t) % mod;
swap(x,y);
}
if(x != i){
for(int k = 0; k < N; k++)
swap(a[i][k], a[x][k]);
sign ^= 1;
}
}
if(a[i][i] == 0) return 0;
else ans = ans * a[i][i] % mod;
}
if(sign) ans *= -1;
if(ans < 0) ans += mod;
return ans;
}
int x[maxn];
int y[maxn];
ll quick_pow(ll a, int b, int mod)
{
ll ans = 1;
for(; b; b >>= 1, a = a * a % mod){
if(b & 1) ans = ans * a % mod;
}
return ans;
}
ll fact[2 * maxm + 5];
ll rev[2 * maxm + 5];
int main()
{
int T;scanf("%d", &T);
fact[0] = 1; rev[0] = 1;
for(int i = 1; i < 2 * maxm; ++i) fact[i] = fact[i - 1] * 1ll * i % mod;
for(int i = 1; i < 2 * maxm; ++i) rev[i] = quick_pow(fact[i], mod - 2, mod);
while(T--){
sign = 0;
int n;scanf("%d%d", &n, &N);
for(int i = 0; i < N; ++i){
scanf("%d", &x[i]);
}
for(int i = 0; i < N; ++i){
scanf("%d", &y[i]);
}
for(int i = 0; i < N; ++i){
for(int j = 0; j < N; ++j){
if(y[j] < x[i]) a[i][j] = 0;
else{
a[i][j] = fact[n - 1 + y[j] - x[i]] * rev[n - 1] % mod * rev[y[j] - x[i]] % mod;
}
}
}
printf("%lld\n", solve() % mod);
}
return 0;
}