Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray.

-----Input:-----
- The first line will contain $T$, number of test cases. Then the test cases follow. 
- The first line of each test case contains two integers $N$ and $K$.
- The next line contains N space-separated integers Ai denoting the elements of the array.

-----Output:-----
Print a single line corresponding to each test case — the length of the largest segment.

-----Constraints-----
- $1 \leq T \leq 10$
- $1 \leq N \leq 10^6$
- $1 \leq Ai, K \leq 10^9$
- Sum of N across all test cases doesn't exceed $10^6$

-----Sample Input:-----
2
5 3
2 4 2 4 2
8 5
9 3 5 7 8 11 17 2

-----Sample Output:-----
5
3

-----EXPLANATION:-----
If 3 is inserted at anywhere in the array, it is the second largest element. Hence the maximum length is 5.
If 5 is inserted anywhere between 1st and 4th element, it is the second largest element. The length of such subarray is 3.

Starter code:

Solutions:
for _ in range(int(input())):
 n,k=list(map(int,input().split()))
 a=list(map(int,input().split()))
 def check(mid):
  d,left={},0
  for i in range(mid):
   if a[i]>k:
    if a[i] not in d: 
     d[a[i]]=1
    else: 
     d[a[i]]+=1
  if len(d)==1:
   return True
  for i in range(mid,n):
   if a[left]>k:
    d[a[left]]-=1
    if d[a[left]]==0: 
     del d[a[left]]
   if a[i]>k:
    if a[i] not in d: 
     d[a[i]]=1
    else: 
     d[a[i]]+=1
   if len(d)==1: 
    return True
   left+=1
  return False
   
 lo,hi=0,n
 while lo<=hi:
  mid=(lo+hi)//2
  #print(mid,lo,hi)
  if check(mid):
   res=mid
   lo=mid+1
  else:
   hi=mid-1
 print(res)
   
   
   


def solve(arr,n,k):
 if max(arr)<=k:
  return 0
 ans=0
 m=-1
 f=0
 
 i=0
 j=-1
 
 while j<n-1:
  if arr[j+1]<=k:
   j+=1
  elif arr[j+1]>k:
   if m==-1:
    m=arr[j+1]
    f+=1
    j+=1
   elif arr[j+1]==m:
    f+=1
    j+=1
   else:
    ans=max(ans,j-i+1)
    while f:
     if arr[i]==m:
      f-=1
     i+=1
    m=-1
    f=0
 ans=max(ans,j-i+1)
 return ans
for _ in range(int(input())):
 n,k=list(map(int,input().split( )))
 arr=list(map(int,input().split( )))
 print(solve(arr,n,k))


# cook your dish here
def answer():
 for t in range(int(input())):
  N, K = [int(x) for x in input().split()]
  l = [-1]
  l += [int(x) for x in input().split()] 
  green = 0
  orange = 0
  red = 0
  ans = 0
  
  
  while True:
   orange +=1
   
   if orange==N+1:
    ans = max(ans, N-green)
    break
   
   elif l[orange]>K: 
    
    red = orange
    while True:
     red+=1
     if red == N+1: 
      ans = max(ans, N-green)
      break
     elif l[red]>K :
      if l[red]!=l[orange]:
       ans = max(ans, red-green-1)
       green = orange
       orange = red-1
       break
      else: orange = red
     
   
   
  print(ans)
 return 
     
  
  


def __starting_point():
 
 
 answer()
__starting_point()

# cook your dish here
for i in range(int(input())):
 n,k = list(map(int,input().split()))
 a = list(map(int,input().split()))
 c,x,i1,i2,b = 0,0,0,0,list()
 for j in range(n):
  c += 1
  if a[j] > k :
   x += 1
   if x == 1 :i1 = j
   else:
    if a[j] == a[i1]:x -= 1
    else:i2 = j
  if x == 2 :
   x = 1
   b.append(c-1)
   c = i2-i1
   i1 = i2
   i2 = 0
  if j == n-1 and b == [ ]:b.append(n)
 print(max(b))
  
 



# cook your dish here
t=int(input())
while t:
 a=input().split()
 n=int(a[0])
 k=int(a[1])
 lst=input().split()
 for i in range(n):
  lst[i] = int(lst[i])
 greater = 0
 length=0
 pos = -1
 allTimeLong=0
 for i in range(n):
  if lst[i]>k and greater!=0 and lst[i]!=greater:
   greater = lst[i]
   if allTimeLong<length:
    allTimeLong=length
   length = i - pos
   pos=i
   continue
  elif lst[i]>k:
   greater = lst[i]
   pos=i
  length+=1
 if allTimeLong<length:
  allTimeLong=length
 t-=1
 print(allTimeLong)

for i in range(int(input())):
 n,k = list(map(int,input().split()))
 a = list(map(int,input().split()))
 c,x,i1,i2,b = 0,0,0,0,list()
 for j in range(n):
  c += 1
  if a[j] > k :
   x += 1
   if x == 1 :i1 = j
   else:
    if a[j] == a[i1]:x -= 1
    else:i2 = j
  if x == 2 :
   x = 1
   b.append(c-1)
   c = i2-i1
   i1 = i2
   i2 = 0
  if j == n-1 and b == [ ]:b.append(n)
 print(max(b))
  
 



for i in range(int(input())):
 n,k = map(int,input().split())
 a = list(map(int,input().split()))
 c,x,i1,i2,b = 0,0,0,0,list()
 for j in range(n):
  c += 1
  if a[j] > k :
   x += 1
   if x == 1 :i1 = j
   else:
    if a[j] == a[i1]:x -= 1
    else:i2 = j
  if x == 2 :
   x = 1
   b.append(c-1)
   c = i2-i1
   i1 = i2
   i2 = 0
  if j == n-1 and b == [ ]:b.append(n)
 print(max(b))

for _ in range(int(input())):
 n,k=list(map(int,input().split()))
 l=[int(i) for i in input().split()]
 maxi=0 
 grtr=0 
 st=0 
 from collections import defaultdict
 big=defaultdict(int)
 for end in range(n):
  if l[end]>k:
   big[l[end]]+=1 
   if big[l[end]]==1:
    grtr+=1 
  while grtr>1:
   if l[st]>k:
    big[l[st]]-=1 
    if big[l[st]]<=0:
     grtr-=1 
   st+=1 
  maxi=max(maxi,end-st+1)
 print(maxi)


for _ in range(int(input())):
 n,k=list(map(int,input().split()))
 l=[int(i) for i in input().split()]
 maxi=0 
 grtr=0 
 st=0 
 from collections import defaultdict
 big=defaultdict(int)
 for end in range(n):
  if l[end]>k:
   big[l[end]]+=1 
   if big[l[end]]==1:
    grtr+=1 
  while grtr>1:
   if l[st]>k:
    big[l[st]]-=1 
    if big[l[st]]<=0:
     grtr-=1 
   st+=1 
  maxi=max(maxi,end-st+1)
 print(maxi)


# cook your dish here
for i in range(int(input())):
 n,k=input().split()
 n=int(n)
 k=int(k)
 arr=list(map(int,input().split()))
 a=0
 b=0
 count=0
 ans=0
 temp=-1
 w=0
 index1=index2=None
 while(b<n):
  if(arr[b]>k):
   if(count==0):
    index1=b
    count+=1 
   else:
    if(arr[b]==arr[index1]):
     index1=b 
    else:
     index2=b 
     count+=1 
  if(count==2):
   w=1
   ans=max(ans,b-a)
   a=index1+1 
   index1=index2
   index2=None 
   count=1 
  b+=1 
 if(w==0 and count==1):
  print(n)
 else:
  print(ans)
    
   
   
 
   
    
   
   


# https://www.codechef.com/problems/SLAEL

for _ in range(int(input())):
 n,k = list(map(int,input().split()))
 ays = list( map(int,input().split()) )

 gt = k # sentinel
 gtp = -1
 mseg = 0
 seg = 0
 for ax,a in enumerate(ays):
  if a <= k:
   seg += 1
  elif a == gt:
   seg += 1
   gtp = ax
  else:
   if seg > mseg:
    mseg = seg
   gt = a
   seg = ax - gtp
   gtp = ax

 if gt == k: # check sentinel
  mseg = 0
 elif seg > mseg:
  mseg = seg
 print(mseg)


import sys

def _int():
 return int(sys.stdin.readline())

def _ints():
 return list(map(int, sys.stdin.readline().split()))

def _intarr():
 return list(map(int, sys.stdin.readline().split()))

def _str():
 return sys.stdin.readline()

def _strarr():
 return sys.stdin.readline().split()

t = _int()

ans = []

for _ in range(t):
 n, m = _ints()
 arr = _intarr()
 
 
 # start index of current calculation
 start = -1
 # end index of current calculation
 # used for edge cases
 end = -1
 # index of previous bigger than m
 # used for calculating start for next
 index = -1
 ans = 0
 for i in range(n):
  if start == -1:
   start = i
   if arr[i] > m:
    index = i
  else:
   if arr[i] > m:
    if index == -1:
     index = i
    elif arr[index] != arr[i]:
     end = i
     # calculate string length
     ans = max(ans, end-start)
     #print("{} {} {}".format(start, end, ans))
     # start new calculation with next element
     # of previos bigger than m
     start = index+1
    # previous bigger than m
    index = i
 if end != n-1:
  end = n
  ans = max(ans, end-start)
  #print("{} {} {}".format(start, end, ans))
 
 print(ans)


t=int(input())
for i in range(t):
 n,k=map(int,input().split())
 a=list(map(int,input().split()))
 lt=list()
 nos=list()
 p=-1
 for j in range(n):
  if a[j]>k:
   nos.append(a[j]) 
   lt.append(j+1)
 lt=[0]+lt+[n+1] 
 l,j=0,0
 tm=len(lt)
 nos=[0]+nos+[nos[tm-3]]
 while(j<tm-2):
  xt=j+2
  while xt+1<tm and nos[xt]==nos[j+1]:
    xt+=1
  ct=lt[xt]-lt[j]-1
  if ct>l:
   l=ct
  j=xt-1 
 print(l)

t=int(input())
while(t>0):
 n,k=[int(x) for x in input().split()]
 a=[int(x) for x in input().split()]
 first=0
 prev=0
 i=0
 len=0
 maxlen=0
 while(i<n):
  if(a[i]>k):
   if(first==0):
    first=a[i]
    prev=i
    len+=1
   else:
    if(first==a[i]):
     len+=1
     prev=i
    else:
     first=0
     i=prev
     if(maxlen<len):
      maxlen=len
     len=0
  else:
   len+=1
  i+=1
 else:
  if(maxlen<len):
   maxlen=len
 print(maxlen)
 t-=1


# https://www.codechef.com/problems/SLAEL

for _ in range(int(input())):
 n,k = list(map(int,input().split()))
 ays = list( map(int,input().split()) )

 gt = 0
 gtp = -1
 mseg = 0
 seg = 0
 for ax,a in enumerate(ays):
  if a<=k:
   seg += 1
  elif gt == 0:
   seg += 1
   gt = a
   gtp = ax
  elif a == gt:
   seg += 1
   gtp = ax
  else:
   if seg > mseg:
    mseg = seg
   gt = a
   seg = ax - gtp
   gtp = ax

 if seg > mseg:
  mseg = seg
 print(mseg)


t=int(input())
for _ in range(t):
 n,k=list(map(int,input().strip().split()))
 a=list(map(int,input().strip().split()))
 c=0
 f=0
 b=[]
 d=[0,0]
 for i in range(n):
  if a[i]>k:
   f+=1
   if f==1:
    d[0]=i
   else:
    if a[i]==a[d[0]]:
     f-=1
    else:
     d[1]=i
  c+=1
  if f==2:
   f=1
   b.append(c-1)
   c=d[1]-d[0]
   d[0]=d[1]
   d[1]=0
 if len(b)==0:
  print(c)
 else:
  print(max(b))


t=int(input())
for i in range(t):
 n,k=list(map(int,input().strip().split()))
 a=list(map(int,input().strip().split()))
 c=0
 x=0
 b=list()
 i1=0
 i2=0
 for j in range(n):
  c+=1
  if a[j]>k:
   x+=1
   if x==1:
    i1=j
   else:
    if a[j]==a[i1]:
     x-=1
    else:
     i2=j
  if x==2:
   x=1
   b.append(c-1)
   c=i2-i1
   i1=i2
   i2=0
  if j==n-1 and b==[ ]:
   b.append(n)
 print(max(b))