The lengths of the bases of an isosceles trapezoid are 40 and 22, and the length of the altitude is 7. Find the length of a leg of the trapezoid.