#include <bits/stdc++.h>
using namespace std;
int n, s[20];

int fc(int x, int y)
{
    if( x == 0 ) return 0;
    if( s[x] == y ) return fc(x-1, y);
    if( s[x] == (y+1)%3 ) return fc(x-1, (y+2)%3) + 1 + (1<<(x-1))-1;
    if( s[x] == (y+2)%3 ) return fc(x-1, (y+1)%3) + 1 + (1<<(x-1))-1;
}
void h(int x, char a, char b, char c)
{
    if( x > 0 ) h(x-1, a, c, b), cout<<"move box "<<x<<" from "<<a<<" to "<<c<<endl, h(x-1, b, a, c);
}
void g(int x, int y)
{
    if( x == 0 ) return;
    if( s[x] == y ) g(x-1, y);
    else if( s[x] == (y+2)%3 )
    {
        g(x-1, (y+1)%3);
        cout<<"move box "<<x<<" from "<<(char)('A'+((y+2)%3))<<" to "<<(char('A'+y))<<endl;
        h(x-1, ('A'+(y+1)%3), ('A'+(y+2)%3), 'A'+y);
    }
    else
    {
        g(x-1, (y+2)%3);
        cout<<"move box "<<x<<" from "<<(char)('A'+((y+1)%3))<<" to "<<(char('A'+y))<<endl;
        h(x-1, ('A'+(y+2)%3), ('A'+(y+1)%3), 'A'+y);
    }
}

int main()
{
    freopen(".15.in","r",stdin);
    freopen(".15.out","w",stdout);
    cin>>n;
    for(int i = 0 ; i < 3 ; i++ )
    {
        int m, t;
        cin>>m;
        for(int j = 0 ; j < m ; j++ )
            cin>>t, s[t] = i;
    }
    cout<<fc(n, 2)<<endl;
    g(n, 2);
}
