The given information tells us that John had 4/7 as many stamps as Ali and Sam had 5/9 as many as Ali.
I personally would set the problem up for solving without those ugly fractions.
I would use the least common multiple of those denominators (63) to set the problem up like this:
Ali's stamps: 63x
John's stamps: 36x (4/7 as many as Ali)
Sam's stamps: 35x (5/9 as many as Ali)
Then use those starting numbers with the given information:
Ali John Sam
--------------------
63x 36x 35x
63x 33x 38x John gave 1/12 of his stamps (3x) to Sam
56x 33x 45x Ali gave 1/9 of his stamps (7x) to Sam
Sam ended up with 180 stamps:
45x=180
x=180/45=4
a) Find the ratio of the number of John's stamps to the number of Sam's stamps at first
ANSWER: 36x:35x = 36:35
b) How many stamps did the three boys have altogether?
ANSWER: 63x+36x+35x=134x=134(4)=536