#include<bits/stdc++.h>

using namespace std;

int main() {
string t, s;
int m, n, i, h;
char x;
cin>>t;
cin>>s;
m=s.length();
n=t.length();
int o[m];
int swapped;
for(i=0; i<=n-1; i++){
o[i%m]=count(t.begin(), t.end(), s[i%m]); 	
}
	while(1){

	swapped=0;
	for(i=0; i<m-1; i++){
	if(o[i]>o[i+1]){
		h=o[i];
		o[i]=o[i+1];
		o[i+1]=h;
		x=s[i];
		s[i]=s[i+1];
		s[i+1]=x;
		swapped=1;
	}	
	}
	if(swapped==0){
		break;
	}
}
for(i=0; i<=n-1; i++){
	if(t[i]==s[0]){
		t[i]='*';
	}
}
cout<<o[0];
cout<<"\n";
cout<<t;
return 0;
}