Let x be the cost of each book.
So, the cost of 4 books is 4x.
For the purchase of 4 books, he got a discount of $20.
So, the amount he paid for the first four books = 4x - 20.
Now, the cost of 5 books is 5x.
For the purchase of 5 books, he got another discount of $5.
So, the amount he paid for the five books = 5x - 5.
Total money spent = $87.
Therefore, (4x - 20) + (5x - 5) = 87
4x + 5x - 20 - 5 = 87
9x - 25 = 87
9x = 87 + 25
9x = 112
Divide both sides by 9.
x = 12.4
Hence, the cost of each book = $12.4.