Let $d,p,q$ be fixed positive integers, and $d$ is not a perfect square. $\mathbb{N}$ is the set of all positive integers, and $S=\{m+n\sqrt{d}|m,n \in \mathbb{N}\} \cup \{0\}$. Suppose the function $f: S \to S$ satisfies the following conditions for all $x,y \in S$: (i) $f((xy)^p)=(f(x)f(y))^p$ (ii)$f((x+y)^q)=(f(x)+f(y))^q$ Find the function $f$.