#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int MAX = 522133279; const double pi = 3.1415926535897; const int mod = 1000000007; char s[100000+100]; int n,T; char res[100000 + 100]; int num[100000 + 100]; int main( ) { scanf("%d", &T ); getchar( ); for ( int cs = 1; cs <= T; cs++ ) { gets( s ); int len = strlen( s ); scanf("%d", &n); getchar(); int tmp = len % n; int line = (len + n - 1) / n; for ( int i = 0; i < n; i++ ) { num[i] = ( (len/n) + (i < len%n) ); } int index=0; res[len] = '\0'; for ( int i = 0; i < n; i++ ) for ( int j = 0; j < num[i]; j++ ) { res[j * n + i] = s[index++]; } printf("Case #%d:\n%s\n",cs, res ); } return 0; }