A chef got 9 bags of onions. The red onions came in bags of 6 and the yellow onions came in bags of 7. If the chef got a total of 59 onions, how many bags of each type of onion did he get?