Help me in solving SRTO3 problem

My issue

what is the problem with this code.

My code

def merge(arr, l, m, r):
	n1 = m - l + 1
	n2 = r - m

	L = [0] * (n1)
	R = [0] * (n2)

	for i in range(0, n1):
		L[i] = arr[l + i]

	for j in range(0, n2):
		R[j] = arr[m + 1 + j]

	i = 0	 
	j = 0	 
	k = l	 

	while i < n1 and j < n2:
		if L[i] <= R[j]:
			arr[k] = L[i]
			i += 1
		else:
			arr[k] = R[j]
			j += 1
		k += 1

	while i < n1:
		arr[k] = L[i]
		i += 1
		k += 1

	while j < n2:
		arr[k] = R[j]
		j += 1
		k += 1
		
def mergeSort(arr, l, r):
	if l < r:
		m = l+(r-l)//2
		mergeSort(arr, l, m)
		mergeSort(arr, m+1, r)
		merge(arr, l, m, r)
		
for _ in range(int(input())):
    n,m = map(int, input().split())
    a = [int(a) for a in input().split()]
    b = [int(b) for b in input().split()]
    for i in range(m):
        mergeSort(a, b[i]+1, n-1)
    for i in a:
        print(i,end=" ")
    print()

Problem Link: ORST Practice Coding Problem - CodeChef

@anuskcse
whats your logic??

take subset of the array and sort just that subset using merge sort (as it uses fair time and space).

@anuskcse
the logic is just pick the maximum length suffix from B and then sort A suffix from that length and print the remaining prefix as it is.
for reference take my c++ solution .
https://www.codechef.com/viewsolution/1040263292