// Arup Guha
// 4/30/2007
// Solution to 2007 UCF HS Problem: Marquee, written in practice contest

import java.util.*;
import java.io.*;

public class marquee {

  public static void main(String[] args) throws IOException {

    Scanner fin = new Scanner(new File("marquee.in"));

    // Process each case.
    int numcases = fin.nextInt();
    for (int i=1; i<=numcases; i++) {

      // Read in sign and print header.
      String wholesign = fin.nextLine();
      wholesign = fin.nextLine();
      int size = fin.nextInt();
      System.out.println("Sign #"+i+":");

      // weird case
      if (wholesign.length() <= size) {
        System.out.print("["+wholesign);
        for (int j=0; j<size-wholesign.length(); j++)
          System.out.print(" ");
        System.out.println("]");
      }

      // regular case
      else {
        wholesign = wholesign+" ";
        for (int j=0; j<wholesign.length(); j++) {
          System.out.print("[");
          for (int k=j; k<j+size; k++)
            System.out.print(wholesign.charAt(k%wholesign.length()));
          System.out.println("]");
        }

      }

      // Skip line between cases.
      System.out.println();
    }

    fin.close();
  }
}