// File: /workspace/github_cpp_makefile_star2_O1/vividvilla[P]hackerrank/src/grid-walking.cpp
// Function: main
int main() {
    int T, N, M, temp;
    cin >> T;

    for (int i = 0; i < T; i++) {
        cin >> N >> M;
        vector<int> x;
        vector<int> d;

        for (int j = 0; j < N; j++) {
            cin >> temp;
            x.push_back(temp);
        }

        for (int j = 0; j < N; j++) {
            cin >> temp;
            d.push_back(temp);
        }

        cout << getWays(x, d, M) << endl;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq 0x279d(%rip), %rdi      # 0x3fe0
leaq 0xc(%rsp), %rbx
movq %rbx, %rsi
callq 0x1060
cmpl $0x0, (%rbx)
jle 0x19fd
movq 0x2780(%rip), %rbx      # 0x3fe0
leaq 0x4(%rsp), %r12
leaq 0x30(%rsp), %r13
leaq 0x10(%rsp), %rbp
xorl %r15d, %r15d
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x1060
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x1060
xorl %eax, %eax
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
cmpl $0x0, (%rsp)
jle 0x18e8
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1060
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x18d4
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x18df
movq %r13, %rdi
movq %r12, %rdx
callq 0x1b04
incl %r14d
cmpl (%rsp), %r14d
jl 0x18ac
cmpl $0x0, (%rsp)
jle 0x192d
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1060
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1919
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x1924
movq %rbp, %rdi
movq %r12, %rdx
callq 0x1b04
incl %r14d
cmpl (%rsp), %r14d
jl 0x18f1
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x1a84
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1a84
movl 0x8(%rsp), %edx
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x124c
movq 0x266e(%rip), %rdi      # 0x3fd0
movl %eax, %esi
callq 0x10f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x19aa
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x19c1
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x19d8
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x19ef
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
incl %r15d
cmpl 0xc(%rsp), %r15d
jl 0x1872
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1a4a
movq %rax, %rbx
jmp 0x1a2f
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x1a2f
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x1a4d
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
jmp 0x1a4d
jmp 0x1a4a
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1a64
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1a7b
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x1100
nop