n=int(input()) s=[] t=[] def f(): if len(t)==n: if all(t.count(c)>0 for c in "ABC"): s.append("".join(t)) else: for c in "ABC": t.append(c) f() if len(t)>0: t.pop() return f() m=int(input())-1 if m