Jamal started with B books in the cart.
He had B - 12 books after the history section.
He had B - 12 - 19 = B - 31 books after the fiction section.
He had B - 31 - 8 + 4 = B - 35 books after the children’s section.
He still had B - 35 = 16 books to shelve.
Thus, he started with B = 16 + 35 = <<16+35=51>>51 books in the cart.
#### 51