You have installed a hack that did not cache the templates properly, read this thread, it covers templates and how to cache them:
https://vborg.vbsupport.ru/showthread.php?t=59939
Secondly, 27 is a large number of queries per page. What exactly is this page doing to be making so many calls to the database!?
Are you in a shared hosting enviroment? Other sites could be using up resources. Or other php files on your site could be eating up resources and casuing long page generation times.
You will also want to look into things like cron scripts and see if a problem might lie there. It may also be possible that for some reason your tables are getting locked and taking awhile to re-open and allow others to read/update them.