
#include<stdio.h>
#include<queue>
#include<math.h>
#include<map>
#include<iostream>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;
#define ll long long
string s1,s2;
struct node
{
string s;
int step;
};
queue<node>q;
int dir[6]={1,-1,2,-2,3,-3};
map<string,int>mp;
void bfs()
{
while(!q.empty())
{
q.pop();
}
mp.clear();
node first;
first.s=s1;
first.step=0;
q.push(first);
while(!q.empty())
{
node nex=q.front();
q.pop();
if(nex.s==s2)
{
cout<<nex.step<<endl;
return ;
}
int len=nex.s.size();
for(int i=0;i<len;i++)
{
for(int j=0;j<6;j++)
{
int nex_step=i+dir[j];
string tmp=nex.s;
if(nex_step>=0&&nex_step<len&&tmp[nex_step]=='*')
{
swap(tmp[i],tmp[nex_step]);
if(mp[tmp]==0)
{
mp[tmp]=1;
node nexx;
nexx.s=tmp;
nexx.step=nex.step+1;
q.push(nexx);
}
}
}
}
}
}
int main()
{
while(cin>>s1>>s2)
{
bfs();
}
}