Let the age of Andy be x.
Age of John = x + 3.
Andy's age five years ago = (x - 5)
John's age five years ago = (x + 3 - 5)
➡️ By condition,
x - 5 + x + 3 - 5 = 27
Or, 2x = 34
Or, x = 17
➡️ John's present age = 17 + 3 = 20.
Andy's present age = 17.
That's it..