#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;
}
