See the attached image to have a look at how the corresponding sides pair up
The red sides pair up to form the ratio (x-3)/2.5
The blue sides pair up to form the ratio 8/2
The similar figures mean that the two ratios are equal
(x-3)/2.5 = 8/2
2(x-3) = 2.5*8
2x-6 = 20
2x = 26
x = 13
Side note: Solving 40 = 4x-12 should lead to 52 = 4x which means x = 13. You subtracted 12 from both sides instead of adding 12 to both sides.