1
3
5 3 4
 6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
 1
3
10 1 5

1
 1
-1
2
2
3
1
 1

t=int(input())
for i in range(t):
      n=int(input())
      z=list(map(int,input().split()))
      k=max(z)
      indx=-1
      for i in range(n):
            if(z[i]!=k):
                  continue
            if(i>0 and z[i-1]!=k):
                  indx=indx+1
            if(i<n-1 and z[i]!=k):
                  indx=indx+1
      print(indx) 