Shelf A had 40 books and Shelf B had 16 books. After Abigail borrowed an equal number of books from Shelf A and Shelf B, there were 3 times as many books on Shelf A than on Shelf B. How many books did Abigail borrow altogether?