Help me in solving COMPRESSVD problem

My issue

for i in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
for i in range(1,len(a)):
if a[i-1]==a[i]:
a.pop(a[i-1])
print(len(a))
whats wrong with this it is giving runtime error

My code

# cook your dish here
for i in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    for i in range(1,len(a)):
        if a[i-1]==a[i]:
            a.pop(a[i-1])
    print(len(a))

Problem Link: COMPRESSVD Problem - CodeChef

@krishp2310
instead of popping count the length.
because when u pop the size of a changes and thus for some value of i it will become out pf bound. This will give u run time error.
plzz refer the following solution.

# cook your dish here
t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    m=1
    for i in range(0,n-1):
        if a[i] != a[i+1]:
            m+=1
    print(m)