#include #include #include #include #define LL long long using namespace std;; const int N = 1e5 + 10; char s[N]; int c[N]; int main() { int m, kase = 1, T; scanf("%d%*c", &T); while (T--) { gets(s); scanf("%d%*c", &m); int l = strlen(s); int n = l / m + 1, t = l % m; for (int i = 0; i < m; ++i) c[i] = n - 1; for (int i = 0; i < t; ++i) c[i]++; char a[n + 10][m + 10]; memset(a, 0, sizeof a); int cur = 0; for (int j = 0; j < m; ++j) for (int i = 0; i < c[j]; ++i) a[i][j] = s[cur++]; printf("Case #%d:\n", kase++); for (int i = 0; i < n; ++i) printf("%s", a[i]); puts(""); } return 0; }