After counter clockwise (or anti-clockwise) rotation, the length of the vector a remains constant.
i.e. |a| at old position =|a| at new position ⇒‌‌(3p)2+(1)2=(p+1)2+(√10)2 ⇒‌‌9p2+1=p2+1+2p+10 ⇒‌‌8p2−2p−10=0⇒4p2−p−5=0 ⇒‌‌(p+1)(4p−5)=0 ⇒‌‌p=‌