#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
typedef struct node{
char c;
int i;
struct node* next;
}Node;
#define N 10
char a[N][N];
int main()
{
string s,str;
Node* headerPtr=NULL;
Node *cur,*pre;
while(cin>>s&&s!="THEEND")
{
int size=s.length();
for(int i=0;i<size;i++)
{
Node* temp=new Node();
temp->c=s[i];
temp->i=i+1;
temp->next=NULL;
pre=cur=headerPtr;
while(cur!=NULL)
{
if(s[i]>=cur->c)
{
pre=cur;
cur=cur->next;
}
else
{
break;
}
}
if(cur==headerPtr)
{
temp->next=headerPtr;
headerPtr=temp;
}
else
{
pre->next=temp;
temp->next=cur;
}
}
cin>>str;
int sizeStr=str.length();
int h=sizeStr/size;
int l=0;
while(headerPtr!=NULL)
{
//cout<<headerPtr->c<<"***"<<headerPtr->i<<endl;
int z=headerPtr->i;
for(int k=0;k<h;k++)
{
a[k][z-1]=str[l];
l++;
}
Node* temp=headerPtr;
headerPtr=headerPtr->next;
delete temp;
}
for(int i=0;i<h;i++)
{
for(int j=0;j<size;j++)
{
cout<<a[i][j];
}
}
cout<<endl;
}
return 0;
}