#include <bits/stdc++.h>
using namespace std;

int main()
{
    char rec[200000];
    char trazena[10];
    cin>>rec>>trazena;
    int d = 0, x = 0;
    for(; d < 10;d++)
    {
        if(trazena[d] < 'a' || trazena[d]>'z')
            break;
    }
    int br = 0;
    if(d == 2)
    {
        int imaA = 0, imaB = 0,l, i = 0;
        for(; i < 200000;i++)
        {
            if(rec[i] < 'a' || rec[i]>'z')
                break;
            if(rec[i] == trazena[0])
            {
                if(imaA == 0) l = i;
                imaA++;
            }
            else if(rec[i] == trazena[1] && imaA) imaB++;
        }
            i--;
            if(imaA > imaB)
            {
                br += imaB;
                for(int j = l; j <= i;j++)
                    if(rec[j] == trazena[1]) rec[j] = '*';
            }
            else
            {
                br += imaA;
                for(int j = l; j < i;j++)
                    if(rec[j] == trazena[0]) rec[j] = '*';
            }
    }
    else if(d==1)
    {
        for(int i = 0; i < 200000;i++)
        {
            if(rec[i] < 'a' || rec[i]>'z')
                break;
            if(rec[i] == trazena[0])
            {
                rec[i] = '*';
                br++;
            }
        }
    }else{
        for(int i = 0; i < 200000; i++)
        {
            if(rec[i] < 'a' || rec[i]>'z')
                break;
            if(rec[i] == trazena[0])
                x++;
            if(x >= d)
            {
                rec[i] = '*';
                br++;
            }
        }

    }

    cout<<br<<"\n"<<rec;
}