GSUB, My code doesnot pass subtask 2 why?

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner s=new Scanner(System.in);
int T=s.nextInt();
while(T–>0)
{
int count=1;
int n=s.nextInt();
int q=s.nextInt();
int[] a=new int[n+1];
for(int i=1;i<=n;i++)
{
a[i]=s.nextInt();
if(i>1 && a[i]!=a[i-1])
count++;
}

        while(q-->0)
        {
            int x=s.nextInt();
            int y=s.nextInt();
            if(x>1 && a[x]!=a[x-1])
            count--;
            if(x<n && a[x]!=a[x+1])
            count--;
            a[x]=y;
             if(x>1 && a[x]!=a[x-1])
            count++;
            if(x<n && a[x]!=a[x+1])
            count++;
            System.out.println(count);
        }
         
    }
}

}