#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
struct Node //结点
{
char operate; //操作
int father; //该结点上一步结点的康托展开
} node[40500];
struct magic //魔板
{
int s[10]; //字符串
int id; //字符串对应的康托展开
};
int fac[10]; //阶乘
int st[10], ed[10]; //初始状态,终止状态
int pos[10]; //初始状态各数字的位置
char op[1000]; //操作过程
//初始化
void init()
{
fac[0] = 1;
for (int i = 1; i <= 8; i++)
fac[i] = fac[i - 1] * i;
for (int i = 0; i < 40500; i++)
node[i].father = -1;
}
//康托展开
int cantor(int* s)
{
int ans = 0;
for (int i = 1; i <= 8; i++)
{
int k = 0;
for (int j = i + 1; j <= 8; j++)
if (s[i] > s[j])
k++;
ans += k * fac[8 - i];
}
return ans;
}
//A操作
void A(int* s)
{
swap(s[1], s[5]);
swap(s[2], s[6]);
swap(s[3], s[7]);
swap(s[4], s[8]);
}
//B操作
void B(int* s)
{
swap(s[3], s[4]);
swap(s[7], s[8]);
swap(s[2], s[3]);
swap(s[6], s[7]);
swap(s[1], s[2]);
swap(s[5], s[6]);
}
//C操作
void C(int* s)
{
swap(s[2], s[3]);
swap(s[2], s[7]);
swap(s[2], s[6]);
}
//广搜,搜索从“12345678”到达其它状态的操作过程
void BFS()
{
queue<magic> q;
magic now, next;
for (int i = 1; i <= 8; i++)
now.s[i] = i;
now.id = 0;
q.push(now);
while (!q.empty())
{
now = q.front();
q.pop();
//执行A操作
next = now;
A(next.s);
next.id = cantor(next.s);
if (node[next.id].father == -1)
{
node[next.id].father = now.id;
node[next.id].operate = 'A';
q.push(next);
}
//执行B操作
next = now;
B(next.s);
next.id = cantor(next.s);
if (node[next.id].father == -1)
{
node[next.id].father = now.id;
node[next.id].operate = 'B';
q.push(next);
}
//执行C操作
next = now;
C(next.s);
next.id = cantor(next.s);
if (node[next.id].father == -1)
{
node[next.id].father = now.id;
node[next.id].operate = 'C';
q.push(next);
}
}
}
int main()
{
char pre[10], post[10];
init();
BFS();
while (cin >> pre >> post)
{
for (int i = 0; i < strlen(pre); i++)
st[i + 1] = pre[i] - '0';
swap(st[5], st[8]);
swap(st[6], st[7]);
for (int i = 1; i <= 8; i++)
pos[st[i]] = i;
for (int i = 0; i < strlen(post); i++)
ed[i + 1] = post[i] - '0';
swap(ed[5], ed[8]);
swap(ed[6], ed[7]);
for (int i = 1; i <= 8; i++)
ed[i] = pos[ed[i]];
int id = cantor(ed);
int cnt = 0;
while (id)
{
op[++cnt] = node[id].operate;
id = node[id].father;
}
for (int i = cnt; i >= 1; i--)
cout << op[i];
cout << endl;
}
return 0;
}