// Solution to "Crypto Columns" by Bob Roos
// Just a brute force no-frills solution!

import java.io.*;


public class Crypto {
  public static int ncols;         // number of columns in the matrix
  public static int nrows;         // number of rows in the matrix (incl key)
  public static char keychars[];   // array rep of key string
  public static char cipherchars[];   // array rep of ciphertext string
  public static char solution[][]; // the character matrix (first row = key)

  // Main input/process/output loop:
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String key;
    while ((key = in.readLine()) != null) {
      if (key.equals("THEEND")) break;

      String cipher = in.readLine();

      ncols = key.length();
      nrows = cipher.length()/ncols + 1;
      keychars = key.toCharArray();
      cipherchars = cipher.toCharArray();
      solution = new char[nrows][ncols];
      System.out.println(decipher());
    }
  }


  // All the work gets done here:
  public static String decipher() {
    // put the key in the first row (I now realize there was no
    // need to do this):
    for (int col = 0; col < ncols; col++) {
      solution[0][col] = keychars[col];
    }

    // Fill in other rows with the ciphertext in column major order:
    for (int col = 0; col < ncols; col++) {
      for (int row = 1; row < nrows; row++) {
        solution[row][col] = cipherchars[(col)*(nrows-1) + row-1];
      }
    }
/********* DEBUGGING **********************
for (int row = 0; row < nrows; row++) {
   for (int col = 0; col < ncols; col++)
     System.out.print(solution[row][col]);
   System.out.println();
}
********* DEBUGGING **********************/

    // Create an index array; we'll invert this according to
    // the sorting of the key:
    int index[] = new int[ncols];
    for (int i = 0; i < ncols; i++)
      index[i] = i;

    // Insertion sort the key (and move the index values accordingly):
    for (int i = 1; i < ncols; i++) {
      char temp = keychars[i];
      int j = i-1;
      while (j >= 0 && temp < keychars[j]) {
        keychars[j+1] = keychars[j];
        index[j+1] = index[j];
        j--;
      }
      keychars[j+1] = temp;
      index[j+1] = i;
    }

    // Now invert the index array:
    int index2[] = new int[ncols];
    for (int i = 0; i < ncols; i++)
      index2[i] = i;

    // Another insertion sort:
    for (int i = 1; i < ncols; i++) {
      int temp = index[i];
      int j = i-1;
      while (j >= 0 && temp < index[j]) {
        index[j+1] = index[j];
        index2[j+1] = index2[j];
        j--;
      }
      index[j+1] = temp;
      index2[j+1] = i;
    }

    // Okay, use index2 to unpack the rows in the correct
    // column ordering:
    String answer = "";
    for (int j = 1; j < nrows; j++) {
      for (int i = 0; i < ncols; i++) {
        int nextcol = index2[i];
        answer += solution[j][nextcol];
      }
    }
    return answer;
  }
}
