Emily went to the store and bought 3 packs of pencils. Each pack contains 12 pencils. After buying the packs, she gave 5 pencils to her friend and then lost 2 pencils on the way home. How many pencils does Emily have left?