Tom and Mary have a total of $120 to spend on books and pens. Tom wants to spend $30 on books and Mary wants to spend $20 on pens. How many books and pens can they buy if they spend the money simultaneously?

If Tom wants to spend $30 on books and Mary wants to spend $20 on pens, they will spend a total of $30+$20 = $<<30+20=50>>50

If they have a total of $120, after buying the books and pens, they will remain with $120-$50 = $<<120-50=70>>70
Since the price of a single book is $30, at $70, Tom and Mary can buy $70/$30= <<70/30=2.3333333333333335>>2 books.
The cost of a single pen is $20. At the remainder $70, they can buy $70/$20= <<70/20=3.5>>3 pens
Since Tom and Mary cannot buy halves of books or pens, they can buy 2 books and 3 pens. Answer: \boxed{5}.