"Humankind cannot gain anything without first giving something in return. To obtain, something of equal value must be lost. That is alchemy's first law of Equivalent Exchange. In those days, we really believed that to be the world's one, and only truth."
-- Alphonse Elric
Now, here we have an equivalent exchange law for triangles which states that two right-angled isosceles triangles of the same color can be made into a square of the same color using Alchemy.
You are given N$N$ right-angled isosceles colored triangles numbered from 1$1$ to N$N$. For each triangle, the two equal sides have a length of 1$1$ unit. The Color of i$i$-th triangle is given by Ci$C_i$.
To create a tower, we choose some consecutive (2×k)+1$2 \times k)+1$ triangles for any k≥0$k \geq 0$. We then pick some 2×k$2 \times k$ of them (these need not be consecutive), and form k$k$ pairs of triangles such that both triangles in pair have the same color. Also, each of the 2×k$2 \times k$ should be in exactly one pair. Then the two triangles in each pair are joined using Alchemy (following the law of equivalent exchange for triangles) to form squares and these k$k$ squares are placed one upon other. The one remaining triangle is placed as a roof to the tower. This results in a tower of the height of k$k$.
Find the maximum height of the tower that can be formed. 
In other words, you should select the largest consecutive segment of triangles, such that you can form a tower using every single one of those triangles. In particular, you leave out one triangle, which will form the roof, and the other triangles should all be paired up such that both triangles in a pair have the same colour.

-----Input:-----
- The first line contains T$T$, the number of test cases. Then the test cases follow. 
- For every test case, the first line contains N$N$ denoting the number of triangles.
- For every test case, the second line contains N$N$ space-separated integers Ci$C_{i}$ denoting the color of the triangles. ( 1≤i≤N$1 \leq i \leq N$).

-----Output:-----
For every test case, output a single integer denoting the maximum height of the tower that can be formed.

-----Constraints-----
- 1≤T≤100$1 \leq T \leq 100$ 
- 1≤N≤105$1 \leq N \leq 10^{5}$ 
- 1≤Ci≤30$1 \leq C_{i} \leq 30$ 
- Sum of N$N$ over all test cases doesn't exceed 5×105$5\times 10^{5}$ 

-----Sample Input:-----
4
14
5 4 2 2 3 2 1 3 2 7 4 9 9 9
3
1 2 1
3
1 1 1
5
1 2 3 4 1

-----Sample Output:-----
3
1
1
0

-----EXPLANATION:-----
- #1$1$: The subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ results in a tower of height 3$3$.
- #2$2$: The subarray [1,2,1]$[ 1, 2, 1 ]$ results in a tower of height 1$1$.
- #3$3$: The subarray [1,1,1]$[ 1, 1, 1 ]$ results in a tower of height 1$1$. 
- #4$4$: The subarrays [1]$[ 1 ]$, [2]$[ 2 ]$ , [3]$[ 3 ]$, [4]$[ 4 ]$ and [1]$[ 1 ]$ all results in a tower of height 0$0$.

The above tower is possible by subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ resulting in a height of 3$3$ in test case 1$1$.

Starter code:

Solutions:
for i in range(int(input())):
    n = int(input())
    c = list(map(int, input().split()))
    d = {}
    d[0] = -1
    parity = 0
    ans = 0
    for i in range(n):
     parity ^= 1 << (c[i]-1)
     for t in range(30):
      x = parity^(1<<t)
      if(x in d.keys()):
       ans = max(ans, i - d[x])
     if parity not in d.keys():
      d[parity] = i
    print(ans//2)

# cook your dish here
for t in range(int(input())):
    n = int(input())
    l = [int(j)-1 for j in input().split()]
    d = dict()
    # st = tuple([0 for i in range(30)])
    st = 0
    d[st] = -1
    ans = 1
    for i in range(n):
     # st = list(st)
     st = st ^ (1 << l[i])
     # st[l[i]] = 1-st[l[i]]
     for j in range(30):
      # st1 = list(st)
      st1 = st
      st1 = st1 ^ (1<<j)
      # st1[j] = 1 - st1[j]
      if st1 in d and d[st1]!=i-1:
       ans = max(ans, i-d[st1])
       # print(i, d[tuple(st1)])
     if st not in d:
      d[st] = i

    print(ans//2)

for t in range(int(input())):
    n = int(input())
    l = [int(j)-1 for j in input().split()]
    d = dict()
    # st = tuple([0 for i in range(30)])
    st = 0
    d[st] = -1
    ans = 1
    for i in range(n):
     # st = list(st)
     st = st ^ (1 << l[i])
     # st[l[i]] = 1-st[l[i]]
     for j in range(30):
      # st1 = list(st)
      st1 = st
      st1 = st1 ^ (1<<j)
      # st1[j] = 1 - st1[j]
      if st1 in d and d[st1]!=i-1:
       ans = max(ans, i-d[st1])
       # print(i, d[tuple(st1)])
     if st not in d:
      d[st] = i

    print(ans//2)

for t in range(int(input())):
    n = int(input())
    c = list(map(int,input().split()))
    dictionary = {0:0}
    parity = 0
    k = 0
    for i in range(n):
     parity ^= (1<<c[i]-1)
     if parity not in dictionary:
      dictionary[parity] = i+1;
     for j in range(30):
      x = parity ^ (1<<j);
      if x in dictionary:
       k=max(k,i-dictionary[x])

    print(k//2)



# cook your dish here
for t in range(int(input())):
    n = int(input())
    l = [int(j)-1 for j in input().split()]
    d = dict()
    # st = tuple([0 for i in range(30)])
    st = 0
    d[st] = -1
    ans = 1
    for i in range(n):
     # st = list(st)
     st = st ^ (1 << l[i])
     # st[l[i]] = 1-st[l[i]]
     for j in range(30):
      # st1 = list(st)
      st1 = st
      st1 = st1 ^ (1<<j)
      # st1[j] = 1 - st1[j]
      if st1 in d and d[st1]!=i-1:
       ans = max(ans, i-d[st1])
       # print(i, d[tuple(st1)])
     if st not in d:
      d[st] = i

    print(ans//2)


from sys import stdin, stdout

for tc_ in range(int(stdin.readline())):
    n=int(stdin.readline())
    a=list(map(int,stdin.readline().split()))
    dic={0:-1}
    ans=last=0
    for i in range(n):
     last^=(1<<(a[i]-1))
     for j in range(30):
      x=last^(1<<j)
      if x in dic:
       ans=max(ans,i-dic[x])
     if last not in dic:
      dic[last]=i
    stdout.write(f"{ans>>1}\n")


# cook your dish here
for t in range(int(input())):
    n = int(input())
    l = [int(j)-1 for j in input().split()]
    d = dict()
    # st = tuple([0 for i in range(30)])
    st = 0
    d[st] = -1
    ans = 1
    for i in range(n):
     # st = list(st)
     st = st ^ (1 << l[i])
     # st[l[i]] = 1-st[l[i]]
     for j in range(30):
      # st1 = list(st)
      st1 = st
      st1 = st1 ^ (1<<j)
      # st1[j] = 1 - st1[j]
      if st1 in d and d[st1]!=i-1:
       ans = max(ans, i-d[st1])
       # print(i, d[tuple(st1)])
     if st not in d:
      d[st] = i

    print(ans//2)

for t in range(int(input())):
    n = int(input())
    l = [int(j)-1 for j in input().split()]
    d = dict()
    # st = tuple([0 for i in range(30)])
    st = 0
    d[st] = -1
    ans = 1
    for i in range(n):
     # st = list(st)
     st = st ^ (1 << l[i])
     # st[l[i]] = 1-st[l[i]]
     for j in range(30):
      # st1 = list(st)
      st1 = st
      st1 = st1 ^ (1<<j)
      # st1[j] = 1 - st1[j]
      if st1 in d and d[st1]!=i-1:
       ans = max(ans, i-d[st1])
       # print(i, d[tuple(st1)])
     if st not in d:
      d[st] = i

    print(ans//2)

for t in range(int(input())):
    n = int(input())
    l = [int(j)-1 for j in input().split()]
    d = dict()
    # st = tuple([0 for i in range(30)])
    st = 0
    d[st] = -1
    ans = 1
    for i in range(n):
     # st = list(st)
     st = st ^ (1 << l[i])
     # st[l[i]] = 1-st[l[i]]
     for j in range(30):
      # st1 = list(st)
      st1 = st
      st1 = st1 ^ (1<<j)
      # st1[j] = 1 - st1[j]
      if st1 in d and d[st1]!=i-1:
       ans = max(ans, i-d[st1])
       # print(i, d[tuple(st1)])
     if st not in d:
      d[st] = i

    print(ans//2)