#include #include #include #include #include #include using namespace std; using namespace std; int dp[2005],score[1005],cost[1005],vis[1005][1005]; int main (void) { int T; scanf ("%d",&T); int cases=1; while (T--) { int b,n; scanf ("%d%d",&b,&n); for (int i=1;i<=n;i++) scanf("%d%d",&score[i],&cost[i]); memset(dp,0,sizeof(dp)); memset(vis,0,sizeof(vis)); long long maxdp=0; for (int i=1;i<=n;i++) { for (int j=b;j>=cost[i];j--) { if (dp[j]0) { if(vis[i][j]) { j-=cost[i]; ans+=cost[i]; count0[len]=i; len++; } i--; } sort(count0,count0+len); printf ("Case #%d:\n",cases++); printf ("%d %d\n",dp[b],ans); for (int i=0;i