#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <list>
#include <set>
using namespace std;
int main(){
const int MAXN = 1e5 + 10;
int i;
char s_decrypt[MAXN];
int T = 0,N=1;
scanf("%d", &T);
while (T--)
{
getchar();
gets(s_decrypt);
scanf("%d", &i);
int len = strlen(s_decrypt);
int v = len % i==0?len/i:len/i+1;
int yu = len%i;
char decrypt[5010];
int z = 0;
int count = 0;
for (int k = 0; k < i; k++)
{
for (int j = 0; j < v; j++)
{
if (k + i*j < len){
decrypt[k + i*j] = s_decrypt[z++];
count++;
}
}
}
decrypt[len] = '\0';
printf("Case #%d:\n%s\n", N++, decrypt);
}
return 0;
}