//
// Created by Naman Bhalla on 29/09/19.
//
#include <bits/stdc++.h>
using namespace std;
int a[101];
int dp[101][101];
int mm[101][101];
int ct[1001];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
for(int cs = 1; cs <= t; ++cs){
cout << "Case #" << cs << ": ";
memset(dp, 0, sizeof dp);
memset(mm, 0, sizeof mm);
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
for(int i = 1; i <= n; ++i){
memset(ct, 0, sizeof ct);
int mmc = 0;
for(int j = i; j <= n; ++j){
++ct[a[j]];
if(ct[a[j]] > mmc){
mmc = ct[a[j]];
}
mm[i][j] = mmc;
}
}
for(int i = 0; i <= n; ++i){
for(int j = 0; j <= n; ++j){
dp[i][j] = INT_MAX;
}
}
dp[0][1] = 0;
for(int i = 1; i <= n; ++i){
dp[i][1] = i - mm[1][i];
}
for(int i = 1; i <= n; ++i){
for(int j = 2; j <= k + 1; ++j){
for(int l = i; l >= 1; --l){
if(dp[l - 1][j - 1] != INT_MAX)
dp[i][j] = min(dp[i][j], (i - l + 1 - mm[l][i]) + dp[l - 1][j - 1]);
}
}
}
int ans = INT_MAX;
for(int j = 1; j <= k + 1; ++j){
ans = min(ans, dp[n][j]);
}
cout << ans << "\n";
}
return 0;
}
Ly8KLy8gQ3JlYXRlZCBieSBOYW1hbiBCaGFsbGEgb24gMjkvMDkvMTkuCi8vCgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgYVsxMDFdOwoKaW50IGRwWzEwMV1bMTAxXTsKaW50IG1tWzEwMV1bMTAxXTsKaW50IGN0WzEwMDFdOwoKaW50IG1haW4oKXsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKE5VTEwpOwogICAgY291dC50aWUoTlVMTCk7CgogICAgaW50IHQ7CiAgICBjaW4gPj4gdDsKCiAgICBmb3IoaW50IGNzID0gMTsgY3MgPD0gdDsgKytjcyl7CiAgICAgICAgY291dCA8PCAiQ2FzZSAjIiA8PCBjcyA8PCAiOiAiOwogICAgICAgIG1lbXNldChkcCwgMCwgc2l6ZW9mIGRwKTsKICAgICAgICBtZW1zZXQobW0sIDAsIHNpemVvZiBtbSk7CgogICAgICAgIGludCBuLCBrOwogICAgICAgIGNpbiA+PiBuID4+IGs7CgogICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgKytpKXsKICAgICAgICAgICAgY2luID4+IGFbaV07CiAgICAgICAgfQoKICAgICAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47ICsraSl7CiAgICAgICAgICAgIG1lbXNldChjdCwgMCwgc2l6ZW9mIGN0KTsKICAgICAgICAgICAgaW50IG1tYyA9IDA7CiAgICAgICAgICAgIGZvcihpbnQgaiA9IGk7IGogPD0gbjsgKytqKXsKICAgICAgICAgICAgICAgICsrY3RbYVtqXV07CiAgICAgICAgICAgICAgICBpZihjdFthW2pdXSA+IG1tYyl7CiAgICAgICAgICAgICAgICAgICAgbW1jID0gY3RbYVtqXV07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBtbVtpXVtqXSA9IG1tYzsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8PSBuOyArK2kpewogICAgICAgICAgICBmb3IoaW50IGogPSAwOyBqIDw9IG47ICsrail7CiAgICAgICAgICAgICAgICBkcFtpXVtqXSA9IElOVF9NQVg7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGRwWzBdWzFdID0gMDsKICAgICAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47ICsraSl7CiAgICAgICAgICAgIGRwW2ldWzFdID0gaSAtIG1tWzFdW2ldOwogICAgICAgIH0KCgogICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgKytpKXsKICAgICAgICAgICAgZm9yKGludCBqID0gMjsgaiA8PSBrICsgMTsgKytqKXsKICAgICAgICAgICAgICAgIGZvcihpbnQgbCA9IGk7IGwgPj0gMTsgLS1sKXsKICAgICAgICAgICAgICAgICAgICBpZihkcFtsIC0gMV1baiAtIDFdICE9IElOVF9NQVgpCiAgICAgICAgICAgICAgICAgICAgICAgIGRwW2ldW2pdID0gbWluKGRwW2ldW2pdLCAoaSAtIGwgKyAxIC0gbW1bbF1baV0pICsgZHBbbCAtIDFdW2ogLSAxXSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGludCBhbnMgPSBJTlRfTUFYOwoKICAgICAgICBmb3IoaW50IGogPSAxOyBqIDw9IGsgKyAxOyArK2opewogICAgICAgICAgICBhbnMgPSBtaW4oYW5zLCBkcFtuXVtqXSk7CiAgICAgICAgfQoKICAgICAgICBjb3V0IDw8IGFucyA8PCAiXG4iOwogICAgfQoKCiAgICByZXR1cm4gMDsKfQ==
NAo4IDIKMzAwIDEwMCAzMDAgMzAwIDIwMCAxMDAgODAwIDUwMAo1IDMKMTAwIDEwMCAxMDAgMTAwIDMKNyAzCjEwIDIwIDQwIDEwIDEwIDMwIDMwCjEwIDIKMzAgMzAgNjAgNjAgOTAgOTAgNjAgNjAgMzAgMzA=
4
8 2
300 100 300 300 200 100 800 500
5 3
100 100 100 100 3
7 3
10 20 40 10 10 30 30
10 2
30 30 60 60 90 90 60 60 30 30