replace temp with query