replaces a p with q element