The length of a rectangle is 12 less than 3 times the width. The perimeter of the rectangle is 40 inches. What is the length and width of the rectangle?