#include <iostream>
#include <vector>
#include <stack>
using namespace std;
class Comp{
public:
bool operator()(const string &a, const string &b) const{
for(int i = 0; i < a.length() && i < b.length(); ++i){
if(a[i] < b[i]) return true;
else if(a[i] > b[i]) return false;
}
return a.length() < b.length();
}
};
template<typename T, typename C>
void sort(vector<T> &v, C comp){
typedef pair<int, int> P;
stack<P> st;
st.push(P(0, v.size()));
while(!st.empty()){
P s = st.top(); st.pop();
if(s.first + 1 == s.second) continue;
string piv = v[(s.first + s.second) / 2];
int i = s.first, j = s.second - 1;
while(true){
while(i < s.second && comp(v[i], piv)) ++i;
while(j >= s.first && comp(piv, v[j])) --j;
if(i >= j) break;
swap(v[i], v[j]);
++i; --j;
}
st.push(P(s.first, i));
st.push(P(i, s.second));
}
}
vector<string> cycle(string s){
vector<string> res;
for(int i = 0; i < s.length(); ++i){
res.push_back(s);
s = s.substr(1) + s[0];
}
return res;
}
int main(void){
string str;// = "apple";
cin >> str;
vector<string> a = cycle(str);
for(int i = 0; i < a.size(); ++i) cout << a[i] << endl;
cout << endl;
sort(a, Comp());
for(int i = 0; i < a.size(); ++i) cout << a[i] << endl;
cout << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RhY2s+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKY2xhc3MgQ29tcHsKICAgIHB1YmxpYzoKICAgIGJvb2wgb3BlcmF0b3IoKShjb25zdCBzdHJpbmcgJmEsIGNvbnN0IHN0cmluZyAmYikgY29uc3R7CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IGEubGVuZ3RoKCkgJiYgaSA8IGIubGVuZ3RoKCk7ICsraSl7CiAgICAgICAgICAgIGlmKGFbaV0gPCBiW2ldKSByZXR1cm4gdHJ1ZTsKICAgICAgICAgICAgZWxzZSBpZihhW2ldID4gYltpXSkgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYS5sZW5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