In a particular triangle, the second side measures 8 more than three times the first side (x), and the third side measures 5 less than the second side. In terms of x, what is the perimeter?