Sunita has lots of tasks pending and she has no time to complete.  She needs your help and wants you complete the task.
You are given a list of integers and two values $N$ and $K$ $-$ the size of array of integers and the numbers of partitions to be made respectively.
You have to partition the list of integers without changing the order of elements ,into exactly $K$ parts. 
Calculate Greatest Common Divisor of all $K$ partition and sum up the gcd values for each partition.
Maximize the sum obtained. 
Can you help Sunita ? 

-----Input:-----
- First line will contain $T$, number of test cases. Then the test cases follow. 
- Each test case contains of a single line of input, two integers $N, K$. 
- Next line contains $N$ integers $-$ the list of integers.

-----Output:-----
For each test case, output in a single line integer $-$ the maximal result.

-----Constraints-----
- $1 \leq T \leq 100$
- $1 \leq N, K \leq 250$
- $1 \leq K \leq N$
- $1 \leq A[i] \leq 1e5$

-----Sample Input:-----
1
4 2
5 6 3 2

-----Sample Output:-----
6

-----EXPLANATION:-----
[5] [6 3 2] is the best partition [5 + GCD(6,3,2)] = 6

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
from sys import stdin, stdout
from math import gcd
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	gr = [[0 for _ in range(n)] for _ in range(n)]
	ans = 0
	k -= 1
	for sz in range(n):
		for i in range(n - sz):
			j = i + sz
			if sz == 0:
				gr[i][j] = a[i]
			else:
				gr[i][j] = gcd(gr[i + 1][j], gr[i][j - 1])
	dp = [[0 for _ in range(n)] for _ in range(k + 1)]
	for i in range(n):
		dp[0][i] = gr[0][i]
	for i in range(1, k + 1):
		for j in range(i, n):
			for par in range(j - 1, -1, -1):
				dp[i][j] = max(dp[i][j], gr[par + 1][j] + dp[i - 1][par])
	print(dp[k][n - 1])