According to the image the addition between q and m should be 14 in, thos would be your first equation
The second equation could be obtained when finding the area of the figure after dividing the figure into 2 rectangles.
solve the second equation for M
replace the value of M into the first equation