// File: /workspace/github_cpp_makefile_star2_O3/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 0x2758(%rip), %rdi      # 0x3fe0
leaq 0xc(%rsp), %rbx
movq %rbx, %rsi
callq 0x1060
cmpl $0x0, (%rbx)
jle 0x1a46
movq 0x273b(%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 0x1976
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1060
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x191d
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x1928
movq %r13, %rdi
movq %r12, %rdx
callq 0x1b4c
incl %r14d
movl (%rsp), %eax
cmpl %eax, %r14d
jl 0x18f5
testl %eax, %eax
jle 0x1976
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1060
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1962
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x196d
movq %rbp, %rdi
movq %r12, %rdx
callq 0x1b4c
incl %r14d
cmpl (%rsp), %r14d
jl 0x193a
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x1acc
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1acc
movl 0x8(%rsp), %edx
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x124c
movq 0x2625(%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 0x19f3
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x1a0a
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1a21
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1a38
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
incl %r15d
cmpl 0xc(%rsp), %r15d
jl 0x18b7
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1a93
movq %rax, %rbx
jmp 0x1a78
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x1a78
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x1a96
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
jmp 0x1a96
jmp 0x1a93
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1aad
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1ac4
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x1100