#include<bits/stdc++.h>
#define ch(a) char(a+49)
using namespace std;
int st,en;
struct node{
int x;
string go;
};
bool vis[1<<16];
queue<node> q;
int input(){
int num=0,num1=0;
for(int i=0;i<4;i++){
char c[4];
scanf("%s",c);
for(int j=0;j<4;j++) num=(num<<1)+(c[j]-48);
}
while(num){
num1=(num1<<1)+(num&1);
num>>=1;
}
return num1;
}
void sw(int &x,int x1,int y1,int x2,int y2){
int f1=(x1<<2)|y1,f2=(x2<<2)|y2,a=(x>>f1)&1,b=(x>>f2)&1;
if(a) x^=(1<<f1);
if(b) x^=(1<<f2);
if(a) x^=(1<<f2);
if(b) x^=(1<<f1);
}
void print(string str){
printf("%d",str.length()>>2);
for(int i=0;i<str.length();i++){
if(!(i&3)) putchar(10);
putchar(str[i]);
}
}
int main(){
st=input();
en=input();
q.push({st,""});
vis[st]=1;
while(!q.empty()){
node now=q.front();
q.pop();
if(now.x==en){
print(now.go);
break;
}
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
int x;
if(j<3){
x=now.x;
sw(x,i,j,i,j+1);
if(!vis[x]){
vis[x]=1;
q.push({x,now.go+ch(i)+ch(j)+ch(i)+ch(j+1)});
}
}
if(i<3){
x=now.x;
sw(x,i,j,i+1,j);
if(!vis[x]){
vis[x]=1;
q.push({x,now.go+ch(i)+ch(j)+ch(i+1)+ch(j)});
}
}
}
}
}
return 0;
}