#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int used[10000];
vector<int> par, dist;
void bfs(int v){
used[v]=1;
dist[v]=0;
queue<int> q;
q.push(v);
while(!q.empty()){
int x=q.front();
q.pop();
int y;
if(x<9000){
y=x+1000;
if(used[y]==0){
q.push(y);
used[y]=1;
dist[y]=dist[x]+1;
par[y]=x;
}
}
if(x%10!=1){
y=x-1;
if(used[y]==0){
q.push(y);
used[y]=1;
dist[y]=dist[x]+1;
par[y]=x;
}
}
y=(x%1000)*10+x/1000;
if(used[y]==0){
q.push(y);
used[y]=1;
dist[y]=dist[x]+1;
par[y]=x;
}
y=x/10+(x%10)*1000;
if(used[y]==0){
q.push(y);
used[y]=1;
dist[y]=dist[x]+1;
par[y]=x;
}
}
}
int main(){
int a,b;
cin>>a>>b;
par.assign(10000,-1);
dist.assign(10000,-1);
bfs(a);
vector<int>ans;
ans.push_back(b);
while(par[b]!=-1){
b=par[b];
ans.push_back(b);
}
reverse(ans.begin(), ans.end());
for(int x:ans){
cout<<x<<endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxhbGdvcml0aG0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCB1c2VkWzEwMDAwXTsKdmVjdG9yPGludD4gcGFyLCBkaXN0Owp2b2lkIGJmcyhpbnQgdil7Cgl1c2VkW3ZdPTE7CglkaXN0W3ZdPTA7CglxdWV1ZTxpbnQ+IHE7CglxLnB1c2godik7Cgl3aGlsZSghcS5lbXB0eSgpKXsKCQlpbnQgeD1xLmZyb250KCk7CgkJcS5wb3AoKTsKCQlpbnQgeTsKCQlpZih4PDkwMDApewoJCQl5PXgrMTAwMDsKCQkJaWYodXNlZFt5XT09MCl7CgkJCXEucHVzaCh5KTsKCQkJdXNlZFt5XT0xOwoJCQlkaXN0W3ldPWRpc3RbeF0rMTsKCQkJcGFyW3ldPXg7Cg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