#include using namespace std; long long get_hash(string s, long long a, long long b) { long long hash = 0LL; for( int i = 0; i < s.length(); i++ ) { hash = (hash*a+s[i])%b; } return hash; } int main() { int N = 4; long long a, b; cin >> a >> b; unordered_map mp; deque que; que.emplace_back(""); while( !que.empty() ) { string crr = que.front(); que.pop_front(); if( crr.length() == N ) { long long hash = get_hash(crr, a, b); if( mp.count(hash) ) { cout << crr << endl; cout << mp[hash] << endl; break; }else { mp[hash] = crr; } }else { for( char c = 'a'; c <= 'z'; c++ ) { que.emplace_back(crr+c); } } } }