#include<bits/stdc++.h>
using namespace std;
const unsigned inf =0x3f3f3f3f;
int n,m;
int a[10005];
unsigned K[10005][5005],dp[10005][5005];
int main()
{
int T;scanf("%d",&T);
for(int Case=1;Case<=T;++Case)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)scanf("%d",a+i);
sort(a+1,a+n+1);
for(int i=0;i<=n;++i)for(int j=0;j<=m;++j)K[i][j]=1,dp[i][j]=0;
for(int i=1;i<=n;++i)
{
dp[i][1]=(a[i]-a[1])*(a[i]-a[1]);
for(int j=2;j<=min(m,i);++j)
{
dp[i][j]=inf;
for(int k=K[i-1][j];k<=i-1;++k)
{
unsigned tmp=dp[k][j-1]+1LL*(a[i]-a[k+1])*(a[i]-a[k+1]);
if(tmp<dp[i][j])
{
K[i][j]=k;
dp[i][j]=tmp;
}
}
}
}
printf("Case %d: %d
",Case,dp[n][m]);
}
}