Tennis balls cost $7 for one can of three balls. DJ gives the cashier $40 to buy balls and receives $12 back in change. How many tennis balls did DJ buy?