Let x= number of books in container X, then there are x-12 books in container Z. Container Y has (x-12)/2, and x=3(x-12)/2. So 2x=3x-36, 36=3x-2x=x, therefore X contains 36 books; Y contains (36-12)/2=12; and Z contains 36-12=24 books.
CHECK
X contains 3 times contents of Y, 3×12=36. OK.
Y contains half of contents of Z, 24/2=12. OK.
Z contains 12 fewer than X, so Z contains 36-12=24. OK. All OK.