For the first integral, you will take $u=f(x)$.
For the second, you will take $\mathrm dv = f''(x) \mathrm dx$.
In each case, you will get $\int f'(x)\cos{(3x)} \, \mathrm dx$ as your integral on the right hand side. Making this integral the subject of each equation, you will find two expressions that must be equal and can be manipulated to get your result.