-----
ARRAY AND DISTINCT ELEMENTS
-----

Chef is multitalented but he mistakenly took part in 2 contest which will take place
at the same time. So while chef is busy at one cooking contest, he wants you to
take part in coding contest. Chef wants u to solve this program for him.

	

You have been given an array of size n. You have to calculate a subarray of size k
with maximum sum having distinct elements same as original array.

		
		

-----Input Format-----

First line contains no. of test cases. Second line contains n and k. Third line
contains array of n integers.


-----Output-----

Print maximum possible sum as stated in question

		
		

-----Example Text Case-----
Input:

1
10 6
8 8 3 5 3 8 5 7 7 7

Output:
37

		

Starter code:

Solutions:
#

for _ in range(int(input())):
 n,k = list(map(int,input().split()))
 arr = list(map(int,input().split()))
 s=set(arr)
 t1=len(s)
 max=-1
 for i in range(n-k+1):
  temp=set(arr[i:i+k])
  #print(temp,i,k+i+1)
  t=len(temp)
  if t1 == t:
   if max<sum(arr[i:k+i]):
    max=sum(arr[i:k+i])
 print(max)


t=int(input())
for _ in range(t):
 n=list(map(int,input().split()))
 k=n[1]
 n=n[0]
 a=list(map(int,input().split()))
 m=-999999999999
 s1=set(a)
 for i in range(0,n-k+1):
  s=sum(a[i:i+k])
  if s>m and set(a[i:i+k])==s1:
   m=s
 print(m)


for _ in range(int(input())):
 n,k=[int(x) for x in input().split()]
 a=list(map(int,input().split()))
 s=set(a)
 s=list(s)
 aa=[]
 f=0
 for i in range(n-k+1):
  f=0
  ss=a[i:i+k]
  for j in range(len(s)):
   if s[j] not in ss:
    f=1
    break
  if f==0:
   aa.append(sum(ss))
 print(max (aa)) 


# cook your dish here
try:
 tc = int(input())
 for i in range(tc):
  n,k = list(map(int,input().split(" ")))
  arr = list(map(int,input().split()))
  set_arr = set(arr)
  max_sum = 0
  for i in range(n):
   if set(arr[i:i+k]) == set_arr:
    max_sum = max(max_sum, sum(arr[i:i+k]))
  print(max_sum)
except:
 pass
  


# cook your dish here
for _ in range(int(input())):
 n,k=map(int,input().split())
 lst=list(map(int,input().split()))
 p=0
 ele=0
 for i in range(n-k+1):
  x=lst[i:i+k]
  d=sum(x)
  dic={j for j in set(x)}
  elm=len(dic)
  #print(x)
  #print(p,ele,d,elm)
  if elm>=ele:
   if ele>ele:
    p=d
   else:
    if d>p:
     p=d
   ele=elm
 print(p)

# cook your dish here
import sys
t=int(input().strip())
for _ in range(t):
 n, k = map(int, input().strip().split())
 array=list(map(int, input().strip().split()))
 cifre={}
 for el in array:
  cifre[el]=0
 for i in range(k):
  cifre[array[i]]+=1 
 flag=0
 for key in cifre:
  if cifre[key]==0:
   flag=1 
   break
 appo=sum(array[:k])
 somma= appo if flag==0 else 0
 for i in range(0,n-k):
  appo+=array[k+i]-array[i]
  cifre[array[i]]-=1 
  cifre[array[k+i]]+=1 
  flag=0
  for key in cifre:
   if cifre[key]==0:
    flag=1 
    break
  if flag==0:
   somma=max(somma,appo)
 print(somma)

t=int(input())
for i in range(t):
 n,k=list(map(int,input().split()))
 arr=list(map(int,input().split()))
 arr1=list(set(arr))

 l=[]
 res=0
 sums=0
 for i in range(k):
  l.append(arr[i])
  sums+= arr[i]
 
 
 if(len(list(set(l)))==len(arr1)):
  res=max(res,sums)
 
 
 for i in range(k,n):
  sums+= (arr[i]-arr[i-k])
  l.remove(arr[i-k])
  l.append(arr[i])
  if(len(list(set(l)))==len(arr1)):
   res=max(res,sums)
 print(res)


from sys import stdin, stdout
input = stdin.readline
from collections import defaultdict as dd
import math
def geti(): return list(map(int, input().strip().split()))
def getl(): return list(map(int, input().strip().split()))
def gets(): return input()
def geta(): return int(input())
def print_s(s): stdout.write(s+'\n')

def solve():
 for _ in range(geta()):
  n,k=geti()
  a=getl()
  occur=dd(int)
  ans=0
  temp=0
  temp_dict=dd(int)
  for i in a:
   occur[i]+=1
  for i in range(k):
   temp+=a[i]
   temp_dict[a[i]]+=1
  if (list(temp_dict.keys()))==(list(occur.keys())):
   ans=max(ans,temp)
  for i in range(k,n):
   temp-=a[i-k]
   temp_dict[a[i-k]]-=1
   if temp_dict[a[i-k]]==0:
    del temp_dict[a[i-k]]
   temp+=a[i]
   temp_dict[a[i]]+=1
   if (list(temp_dict.keys()))==(list(occur.keys())):
    ans=max(ans,temp)
  print(ans)


def __starting_point():
 solve()

__starting_point()

for _ in range(int(input())):
 n,k=map(int,input().split())
 a=list(map(int,input().split()))
 b=len(set(a))
 m=[]
 for i in range(n-k+2):
  if b == len(set(a[i:i+k])):
   m.append(sum(a[i:i+k]))
 print(max(m))

for ts in range(int(input())):
 n,k=map(int,input().split())
 l=list(map(int,input().split()))
 c=len(set(l))
 su=[]
 for i in range(n-k+2):
  if len(set(l[i:i+k]))==c:
   su.append(sum(l[i:i+k]))
  else:
   pass
 print(max(su))

# cook your dish here
for u in range(int(input())):
 n,k=list(map(int,input().split()))
 l=list(map(int,input().split()))
 m=0
 s=set(l)
 r=len(s)
 for i in range(n-k+1):
  c=0
  d=set()
  for j in range(i,i+k):
   c+=l[j]
   d.add(l[j])
  if(len(d)==r):
   m=max(m,c)
 print(m)


# cook your dish here
test=int(input())
for p in range(test):
 l=list(map(int,input().split()))
 n=l[0]
 k=l[1]
 l=[]
 a=[]
 maxim=0
 l=list(map(int,input().split()))
 d=[]
 for i in l:
  if i not in d:
   d.append(i)
 for i in range(0,len(l)-k+1):
  x=l[i:i+k]
  #print(x)
  flag=0
  for j in d:
   if j not in x:
    flag=1
    break
  if sum(x)>maxim and flag==0:
   maxim=sum(x)
   a=x[:]
 #print(a)
 print(maxim)

# cook your dish here
n = int(input())
while n > 0:
 line1 = [int(x) for x in input().split()]
 arr = [int(x) for x in input().split()]
 ac = len(set(arr))
 ln = line1[0]
 k = line1[1]
 i = 0
 j = k-1
 maxi = -1
 while(j < ln):
  if len(set(arr[i:j+1])) == ac:
   maxi = max(maxi,sum(arr[i:j+1]))
  i += 1
  j += 1
 print(maxi)
 n -= 1

x=int(input())
for i in range(x):
 n,k=map(int,input().split())
 l=list(map(int,input().split()))
 j=0
 m=0
 while j+k<=n:
  #print(set(l[j:j+k]),set(l))
  if m<sum(l[j:j+k]) and set(l[j:j+k])==set(l):
   m=sum(l[j:j+k])
  j+=1
 print(m)

def f():
 n,k=list(map(int,input().split()))
 a=list(map(int,input().split()))
 distinctitem=len(set(a))
 count=[0]*1000000
 temp=[]
 maxi=0
 s=0
 c=0
 for i in range(0,len(a)):
  if len(temp)<k:
   temp.append(a[i])
   if count[a[i]]==0:
    count[a[i]]+=1
    c+=1
    s+=a[i]
   else:
    count[a[i]]+=1
    s+=a[i]
  #print(temp,s)
  if len(temp)==k:
   if c==distinctitem:
    maxi=max(maxi,s)
   s-=temp[0]
   count[temp[0]]-=1
   if count[temp[0]]==0:
    c-=1
   temp.pop(0)
  
 print(maxi)
for i in range(int(input())):
 f()
    
  


# cook your dish here
t=int(input())
while t>0 :
 n,k=map(int,input().split())
 l=list(map(int,input().split()))
 dis=len(set(l))
 a=0
 for i in range(n-k+1) :
  ls=[]
  s=0
  for j in range(k) :
   s+=l[i+j]
   if l[i+j] in ls :
    pass
   else :
    ls.append(l[i+j])
  if len(ls)==dis :
   a=max(a,s)
 print(a)
 t-=1

# cook your dish here
for _ in range(int(input())):
 n, k = input().split()
 n,k = int(n), int(k)
 nums = list(map(int, input().split()))

 length1 = len(set(nums))
 i=0
 j=k-1
 initial = sum(nums[i:j+1])
 if len(set(nums)) == length1:
  m = initial
 else:
  m = 0
 while j<len(nums):
  # print(i,j,initial)
  j+=1
  if j==len(nums):
   break
  initial-=nums[i]
  i+=1
  initial+=nums[j]
  if len(set(nums[i:j+1]))==length1:
   m = max(m, initial)

 print(m)

t = int(input())
for z in range(t):
 first = list(map(int,input().split()))
 second = list(map(int,input().split()))
 length = len(set(second))
 req = 0
 sumi = 0
 for i in range(first[1]):
  req = req+second[i]
 if(length==len(set(second[0:first[1]]))):
  sumi = req
 cp = 0
 for i in range(first[1]+1, first[0]+1):
  req = req - second[cp]+second[i-1]
  if(length == len(set(second[cp+1:i]))):
   if(sumi<req):
    sumi=req
  cp = cp+1
 print(sumi)


# cook your dish here
while True:
 try:
  
  t=int(input())
  h=1 
  while(h<=t):
   n,k=list(map(int,input().split()))
   lis=list(map(int,input().split()))
 
   unique_data=[]
   for i in lis:
    if i not in unique_data:
     unique_data.append(i)
   #print(unique_data)
 
   maxi=0
   lis2=[]
   for i in range(0,n-k+1):
    lis2=lis[i:i+k]
    #print(lis2)
    t=0
    for i in set(lis2):
     if i in unique_data:
      t+=1
   #print(t)
    if(t==len(unique_data)):
     if(sum(lis2)>maxi):
      maxi=sum(lis2)

   print(maxi)
   h+=1
 except:
  break
    
  
  


# cook your dish here
for _ in range(int(input())):
 n,k=list(map(int,input().split()))
 a=list(map(int,input().split()))
 slen=len(set(a))
 lmax=-9
 for i in range(n-k+1):
  x=set(a[i:i+k])
  if len(x)==slen:
   add=sum(a[i:i+k])
   if add>lmax:
    lmax=add
 print(lmax)


T = int(input())

for t in range(T):
 
 n, k = map(int, input().split())
 
 arr = list(map(int, input().split()))
  
 out1 = set(arr)
 
 minSum = sum(arr[0:k])
 
 for i in range(1, n-k+1):
  
  temp = arr[i:i+k]
  
  out = set(temp)
  
  if(len(out) == len(out1)):
   currentSum = sum(temp)
   if minSum < currentSum:
    minSum = currentSum
 print(minSum)

T = int(input())

for t in range(T):
 
 n, k = map(int, input().split())
 
 arr = list(map(int, input().split()))
  
 out1 = set(arr)
 
 minSum = sum(arr[0:k])
 
 for i in range(1, n-k+1):
  
  temp = arr[i:i+k]
  
  out = set(temp)
  
  if(len(out) == len(out1)):
   currentSum = sum(temp)
   if minSum < currentSum:
    minSum = currentSum
 print(minSum)

for _ in range(int(input())):
 n,k=map(int,input().split())
 a=list(map(int,input().split()))
 length=len(set(a))
 tot=sum(a[:k-1])
 tmp=0
 ans=0
 for i in range(k-1,n):
  tot+=a[i]-tmp
  if len(set(a[i-k+1:i+1]))==length:
   ans=max(ans,tot)
  tmp=a[i-k+1]
 print(ans)