/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-12
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 105
#define nm 1000005
#define pi 3.1415926535897931
using namespace std;
const int inf=1000000007;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
int a[NM],d[NM][NM],n;
bool v[NM][NM];
int dp(int x,int y){
if(x>y)return 0;if(x==y)return 1;
if(v[x][y])return d[x][y];v[x][y]++;
d[x][y]=dp(x+1,y)+1;
inc(k,x+1,y)if(a[x]==a[k])d[x][y]=min(d[x][y],dp(x,k-1)+dp(k+1,y));
else if(k<y)d[x][y]=min(d[x][y],dp(x,k)+dp(k+1,y));
// printf("%d %d:%d\n",x,y,d[x][y]);
return d[x][y];
}
int main(){
int _=read();inc(p,1,_){
n=read();mem(v);mem(d);
inc(i,1,n)a[i]=read();
printf("Case %d: %d\n",p,dp(1,n));
}
return 0;
}