Let J be the amount John had at the start, and let M be the amount Mark had at the start.

So J/5 = 3M/4

Then if J' is the amount that John had after the buying and selling, and M' is the amount Mark had after buying and selling, then the 5:3 ratio tells us that

3J'/8 = 5M'/8

We also know that J' = J - 150

and M' = M + 160.

So if we replace J' and M' with those

we get:

So we have two simultaneous equations with two unknowns:

And solve...