John bought 7 rulers and 12 magnets with 1/3 of his savings. The

cost of a magnet is 3 times the cost of a ruler. He used 2/3 of his
remaining allowance to buy more rulers. Hence, how many rulers did
he buy altogether?

If his savings was $s, then if the cost of magnets and rulers are m and r,

m = 3r
7r+12m = s/3
33r = s/3
s = 99r
so he spent 2/9 of 99r = 22r/r for 22 more rulers
so he got 7+22 = 29 rulers in all