#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); auto move = [&](char c,int add) -> char { int v = c-'A'; v += add,v %= 26; return v+'A'; }; vector> S1(26),S2(26),S3(26),S4(26); for(int d=0; d<26; d++){ if(d == 0){ for(char c='A'; c<='Z'; c++){ string s = ""; s += c; S1.at(c-'A').push_back(s); } } else for(char c='A'; c<'A'+gcd(26,d); c++){ string s = ""; char now = c; s += now; now = move(now,d); while(now != c) s += now,now = move(now,d); if(gcd(26,d) == 13) S2.at(c-'A').push_back(s); if(gcd(26,d) == 2) S3.at(c-'A').push_back(s); if(gcd(26,d) == 1) S4.at(c-'A').push_back(s); } } auto dfs = [&](auto dfs,int pos) -> void { for(auto s : S1.at(pos)){ int n = s.size(); for(int i=0; i