Chef and Rainbow Array, why is it giving 1st subtas correct and onother one is wrong

t=int(input())
for i in range(t):
(flag1,flag2)=(0,0)
n=int(input())
a=[int(x) for x in input().split()]
k=n//2
if a[k]==7:
u=a[:k]
if n&1:
v=a[k+1:]
else:
v=a[k:]
v.reverse()
for j in range(len(u)-1):
if u[j+1]==u[j] or u[j+1]==u[j]+1:
continue
else:
break
else:
flag1=1
for j in range(len(v)-1):
if v[j+1]==v[j] or v[j+1]==v[j]+1:
continue
else:
break
else:
flag2=1
if u==v and flag1==1 and flag2==1:
print(“yes”)
else:
print(“no”)
else:
print(“no”)

//