There are players standing in a row each player has a digit written on their T-Shirt (multiple players can have the same number written on their T-Shirt).   
You have to select a group of players, note that players in this group should be standing in $\textbf{consecutive fashion}$. For example second player of chosen group next to first player of chosen group, third player next to second and similarly last player next to second last player of chosen group. Basically You've to choose a contiguous group of players.
After choosing a group, players can be paired if they have the same T-Shirt number (one player can be present in at most one pair), finally the chosen group is called “good” if at most one player is left unmatched. Your task is to find the size of the maximum “good” group.
Formally, you are given a string $S=s_{1}s_{2}s_{3}...s_{i}...s_{n}$ where $s_{i}$ can be any digit character between $'0'$ and $'9'$ and $s_{i}$ denotes the number written on the T-Shirt of $i^{th}$ player. Find a value $length$ such that there exist pair of indices $(i,j)$ which denotes $S[i...j]$ is a “good” group where $i\geq1$ and $j\leq S.length$ and $i\leq j$ and $(j-i+1)=length$ and there exist no other pair $(i’,j’)$ such that $(j’-i’+1)>length$ and $S[i'...j']$ is a "good" group.

-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow. 
- $i^{th}$ testcase consist of a single line of input, a string $S$. 

-----Output:-----
For each testcase, output in a single line maximum possible size of a "good" group.

-----Constraints-----
$\textbf{Subtask 1} (20 points)$
- $1 \leq T \leq 10$
- $S.length \leq 10^{3}$
$\textbf{Subtask 2} (80 points)$
- $1 \leq T \leq 10$
- $S.length \leq 10^{5}$

-----Sample Input:-----
1

123343

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

-----EXPLANATION:-----
1$\textbf{$\underline{2 3 3}$}$43
Underlined group is a “good” group because the second player(number 2 on T-Shirt) is the only player who is left unmatched and third and fourth player can form a pair, no other group has length greater than 3 that are “good”. However note that we have other “good” group also 12$\textbf{$\underline{334}$}$3 but length is 3 which is same as our answer.

-----Sample Input:-----
1

95665

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

-----EXPLANATION:-----
$\textbf{$\underline{95665}$}$ is “good” group because first player is the only player who is left unmatched second and fifth player can form pair and third and fourth player also form pair.

-----Sample Input:-----
2

2323

1234567

-----Sample Output:-----
4

1

-----EXPLANATION:-----
For first test case
$\textbf{$\underline{2323}$}$ is a “good” group because there are no players who are left unmatched first and third player form pair and second and fourth player form pair.

For second test

Only length one "good" group is possible.

Difficulty: interview

Starter code:

Solutions:
import sys

def GRIG(L):

    LENT = len(L)
    MINT = 1
    GOT = 0

    DY = [ [{x: 0 for x in range(0, 10)}, 0, 0] ]

    for i in L:

        DY.append([{x: 0 for x in range(0, 10)}, 0, 0])
        GOT += 1

        for j in range(0, GOT):

            if DY[j][0][i] == 1:
                DY[j][0][i] = 0
                DY[j][1] -= 1
            else:
                DY[j][0][i] = 1
                DY[j][1] += 1

            DY[j][2] += 1

            if DY[j][1] <= 1 and DY[j][2] > MINT:
                MINT = DY[j][2]

    return MINT

TESTCASES = int(input().strip())

for i in range(0, TESTCASES):
    
    L = [int(x) for x in list(input().strip())]
    
    print(GRIG(L))


import sys
import math
from collections import defaultdict,Counter

# input=sys.stdin.readline
# def print(x):
#     sys.stdout.write(str(x)+"\n")

# sys.stdout=open("CP1/output.txt",'w')
# sys.stdin=open("CP1/input.txt",'r')

def possible(n1,n):
	# d=defaultdict(int)
	odd=set()
	# even=set()
	for j in range(n):
		# print(odd)
		if s[j] in odd:
			odd.remove(s[j])
			# even.add(s[j])
		else:
			odd.add(s[j])
		# d[s[j]]+=1
		# print(odd)
		if j<n1-1:
			continue
		# print(j)
		if len(odd)<=1:
			return True

		if s[j-n1+1] in odd:
			odd.remove(s[j-n1+1])
			# even.add(s[j])
		else:
			odd.add(s[j-n1+1])
	return False
# m=pow(10,9)+7
t=int(input())
for i in range(t):
	s=input().strip()
	n=len(s)
	ans=0
	for j in range(n,0,-1):
		if possible(j,n):
			ans=j
			break
	print(ans)
	# low=1
	# high=n
	# while low<=high:
	# 	mid=(low+high)//2
	# 	if mid%2==0:
	# 		if low%2==0:
	# 			low+=1
	# 			mid+=1
	# 		elif high%2==0:
	# 			high-=1
	# 			mid-=1
	# 	# if low>high:
	# 	# 	break
	# 	if possible(mid,n):
	# 		low=mid+1
	# 	else:
	# 		high=mid-1
	# 	print(mid,low,high)
	# print(mid)


import sys
import math
from collections import defaultdict,Counter

# input=sys.stdin.readline
# def print(x):
#     sys.stdout.write(str(x)+"\n")

# sys.stdout=open("CP1/output.txt",'w')
# sys.stdin=open("CP1/input.txt",'r')

def possible(n1,n):
	# d=defaultdict(int)
	odd=set()
	# even=set()
	for j in range(n):
		# print(odd)
		if s[j] in odd:
			odd.remove(s[j])
			# even.add(s[j])
		else:
			odd.add(s[j])
		# d[s[j]]+=1
		# print(odd)
		if j<n1-1:
			continue
		# print(j)
		if len(odd)<=1:
			return True

		if s[j-n1+1] in odd:
			odd.remove(s[j-n1+1])
			# even.add(s[j])
		else:
			odd.add(s[j-n1+1])
	return False
# m=pow(10,9)+7
t=int(input())
for i in range(t):
	s=list(input())
	n=len(s)
	ans=1
	for j in range(n,1,-1):
		if possible(j,n):
			ans=j
			break
	print(ans)
	# low=1
	# high=n
	# while low<=high:
	# 	mid=(low+high)//2
	# 	if mid%2==0:
	# 		if low%2==0:
	# 			low+=1
	# 			mid+=1
	# 		elif high%2==0:
	# 			high-=1
	# 			mid-=1
	# 	# if low>high:
	# 	# 	break
	# 	if possible(mid,n):
	# 		low=mid+1
	# 	else:
	# 		high=mid-1
	# 	print(mid,low,high)
	# print(mid)


from collections import defaultdict
t = int(input())
for _ in range(t):
    s = input()
    s = list(s)
    l = s[:]
    n = len(s)
    ans = 0
    if n<=1000:
        if n<=100:
            l = []
            for i in range(n):
                for j in range(i+1,n):
                    l.append(s[i:j])
            ans = 0
            for i in l:
                dic = defaultdict(lambda:0)
                for j in i:
                    dic[j]+=1
                cnt = 0
                for k in dic.keys():
                    if dic[k]%2==1:
                        cnt+=1
                if cnt<=1:
                    ans = max(ans,len(i))
            print(ans)
            continue
        for i in range(n):
            dic = defaultdict(lambda:0)
            unmatched = 0
            for j in range(i,n):
                dic[l[j]]+=1 
                if dic[l[j]]%2==1:
                    unmatched+=1
                else:
                    unmatched-=1 
                if unmatched<=1:
                    ans = max(ans,j-i+1) 
        
        print(ans)
    else:
        for i in range(n):
            dic = defaultdict(lambda:0)
            unmatched = 0
            for j in range(i+1,n):
                dic[l[j]]+=1 
                if dic[l[j]]%2==1:
                    unmatched+=1
                else:
                    unmatched-=1 
                if unmatched<=1:
                    ans = max(ans,j-i+1) 
        
        print(ans)

import sys
import math
from collections import defaultdict,Counter

# input=sys.stdin.readline
# def print(x):
#     sys.stdout.write(str(x)+"\n")

# sys.stdout=open("CP1/output.txt",'w')
# sys.stdin=open("CP1/input.txt",'r')

def possible(n1,n):
	# d=defaultdict(int)
	odd=set()
	# even=set()
	for j in range(n):
		# print(odd)
		if s[j] in odd:
			odd.remove(s[j])
			# even.add(s[j])
		else:
			odd.add(s[j])
		# d[s[j]]+=1
		# print(odd)
		if j<n1-1:
			continue
		# print(j)
		if len(odd)==1:
			return True

		if s[j-n1+1] in odd:
			odd.remove(s[j-n1+1])
			# even.add(s[j])
		else:
			odd.add(s[j-n1+1])
	return False
# m=pow(10,9)+7
t=int(input())
for i in range(t):
	s=list(input())
	n=len(s)
	ans=1
	for j in range(n,1,-1):
		if possible(j,n):
			ans=j
			break
	print(ans)
	# low=1
	# high=n
	# while low<=high:
	# 	mid=(low+high)//2
	# 	if mid%2==0:
	# 		if low%2==0:
	# 			low+=1
	# 			mid+=1
	# 		elif high%2==0:
	# 			high-=1
	# 			mid-=1
	# 	# if low>high:
	# 	# 	break
	# 	if possible(mid,n):
	# 		low=mid+1
	# 	else:
	# 		high=mid-1
	# 	print(mid,low,high)
	# print(mid)


import sys

def GRIG(L):

    MINT = 1
    GOT = 0

    DY = [[set(), 0, 0]]
    L_DY = 0

    for i in L:

        L_DY += 1
        DY.append([set(), 0, 0])

        for j in range(L_DY - 1, -1, -1):
            if i in DY[j][0]:
                DY[j][0].remove(i)
                DY[j][1] -= 1
            else:
                DY[j][0].add(i)
                DY[j][1] += 1

            DY[j][2] += 1
            if (DY[j][2] > MINT and DY[j][1] <= 1):
                MINT = DY[j][2]

    return MINT

TESTCASES = int(input().strip())

for i in range(0, TESTCASES):
    
    L = [int(x) for x in list(input().strip())]
    
    print(GRIG(L))


from collections import defaultdict
t = int(input())
for _ in range(t):
    s = input()
    s = list(s)
    l = s[:]
    n = len(s)
    ans = 0
    
    if n<=100:
        l = []
        for i in range(n):
            for j in range(i+1,n):
                l.append(s[i:j])
        ans = 0
        for i in l:
            dic = defaultdict(lambda:0)
            for j in i:
                dic[j]+=1
            cnt = 0
            for k in dic.keys():
                if dic[k]%2==1:
                    cnt+=1
            if cnt<=1:
                ans = max(ans,len(i))
        print(ans)
        continue
    for i in range(n):
        dic = defaultdict(lambda:0)
        unmatched = 0
        for j in range(i,n):
            dic[l[j]]+=1 
            if dic[l[j]]%2==1:
                unmatched+=1
            else:
                unmatched-=1 
            if unmatched<=1:
                ans = max(ans,j-i+1) 
            
        
    print(ans)

from sys import stdin

#stdin = open("input", "r")

for _ in range(int(stdin.readline())):
    s = stdin.readline().strip()
    m = 1
    for i in range(len(s)):
        k = set()
        k.add(s[i])
        for j in range(i + 1, len(s)):
            if s[j] in k:
                k.remove(s[j])
            else:
                k.add(s[j])
            if len(k) < 2:
                m = max(m, j - i + 1)
    print(m)


# cook your dish here
def isgood(s):
    c=0
    for i in set(s):
        k=s.count(i)
        if k%2 and c:
            return 0
        elif k%2:
            c=1
    #print(s)
    return 1
tc=int(input())
for i in range(tc):
    flag=0
    s=input()
    n=len(s)
    g=n
    while g:
        for i in range(n-g+1):
            if isgood(s[i:i+g]):
                print(g)
                flag=1
                break
        g-=1
        if flag:
            break


# cook your dish here
def isgood(s):
    c=0
    for i in set(s):
        k=s.count(i)
        if k%2:
            c+=1 
        if c==2:
            return 0
    #print(s)
    return 1
tc=int(input())
for i in range(tc):
    flag=0
    s=input()
    n=len(s)
    g=n
    while g:
        for i in range(n-g+1):
            if isgood(s[i:i+g]):
                print(g)
                flag=1
                break
        g-=1
        if flag:
            break


# cook your dish here
def isgood(s):
    c=0
    for i in set(s):
        k=s.count(i)
        if k%2:
            c+=1 
        if c==2:
            return 0
    #print(s)
    return 1
tc=int(input())
for i in range(tc):
    flag=0
    s=input()
    n=len(s)
    g=n
    while g:
        for i in range(n-g+1):
            if isgood(s[i:i+g]):
                print(g)
                flag=1
                break
        g-=1
        if flag:
            break