Can anybody help me where I am wrong with this code this is link to question https://www.codechef.com/problems/ICM2004 and here is my code

MOD=1000000007
for _ in range(int(input())):
N=int(input())
S=input()
for j in range(int(input())):
l=input().split()
L=int(l[1])
R=int(l[2])
if l[0]==‘2’:
p=int(l[3])
q=int(l[4])
for k in S[L-1:R]:
if k==‘A’:
p1=(p-q+MOD)%MOD
q1=(p+q)%MOD
elif k==‘B’:
p1=(p+q)%MOD
q1=(q-p+MOD)%MOD
p=p1
q=q1
print(p,end=" ")
print(q)
if l[0]==‘1’:
S=S[:L-1]+l[3]*((R-L)+1)+S[R:]
This is link to problem