#include<bits/stdc++.h>
using namespace std;
struct doge {
string now,ans;
int cnt;
} k,t;
string s,CyaNgw;
int dis[100]= {2,5, 3,6, 4,7, 8,
6,9, 7,10, 8,11, 12,
10,13, 11,14, 12,15, 11,16,
14, 15, 16
};
int Q;
int cnt[20]= {0,2,4,6,7 ,9,11,13,14, 16,18,20,22, 23,24,25};
queue<doge>q;
string did[20]= {"0","1","2","3","4"};
map <string,bool > vis;
main() {
for(int i=1; i<=4; i++)cin>>s,k.now+=s;
for(int i=1; i<=4; i++)cin>>s,CyaNgw+=s;
q.push(k);
while(!q.empty()) {
k=q.front();
q.pop();
k.cnt++;
for(int x=1; x<=4; x++)
for(int y=0; y<=3; y++) {
Q=(x-1)*4+y;
for(int i=cnt[Q]; i<=cnt[Q+1]-1; i++) {
t=k;
if(t.now[Q]!=t.now[dis[i]-1]) {
swap(t.now[Q],t.now[dis[i]-1]) ;
if(!vis[t.now]) {
vis[t.now]=1;
t.ans+=did[x]+did[y+1];
if(abs(dis[i]-1-Q)==0)
t.ans+=did[x+1]+did[y+1];
else
t.ans+=did[x]+did[y+2];
q.push(t);
}
}
}
}
if(k.now==CyaNgw) {
cout<<k.cnt-1;
for(int i=0; i<k.ans.length(); i++) {
if(i%4==0)cout<<endl;
cout<<k.ans[i];
}
return 0;
}
}
}