A, B appear once
Choose any 2 of 3 positions for them = C(3,2) = 3 and arrange each of these in 2 ways
And for each of these arrangements, we have 2 choices for the remaining letter (C or D)
So 3 * 2 * 2 = 12 words
ABX AXB XAB
BAX BXA XBA
(2 choices for X in each case)
A or B appear twice
Choose 2 of the 3 positions for either letter = 2*C(3,2) = 6
And for each of these....we have 1 choice (only B or A)
So 6 * 1 = 6 words
AAX AXA XAA
BBX BXB XBB
(1 choice for X in ieach case)
I get 12 + 6 = 18 "words" (same as EnchantedLava )