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.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'import sys\n\ndef _int():\n return int(sys.stdin.readline())\n\ndef _ints():\n return list(map(int, sys.stdin.readline().split()))\n\ndef _intarr():\n return list(map(int, sys.stdin.readline().split()))\n\ndef _str():\n return sys.stdin.readline()\n\ndef _strarr():\n return sys.stdin.readline().split()\n\nt = _int()\n\nans = []\n\nfor _ in range(t):\n n, m = _ints()\n arr = _intarr()\n \n \n # start index of current calculation\n start = -1\n # end index of current calculation\n # used for edge cases\n end = -1\n # index of previous bigger than m\n # used for calculating start for next\n index = -1\n ans = 0\n for i in range(n):\n  if start == -1:\n   start = i\n   if arr[i] > m:\n    index = i\n  else:\n   if arr[i] > m:\n    if index == -1:\n     index = i\n    elif arr[index] != arr[i]:\n     end = i\n     # calculate string length\n     ans = max(ans, end-start)\n     #print("{} {} {}".format(start, end, ans))\n     # start new calculation with next element\n     # of previos bigger than m\n     start = index+1\n    # previous bigger than m\n    index = i\n if end != n-1:\n  end = n\n  ans = max(ans, end-start)\n  #print("{} {} {}".format(start, end, ans))\n \n print(ans)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14245