This question already has an answer here:
Hint. For every real number $r$ there is a rational sequence $(q_n)$ such that $q_n\to r$ as $n\to\infty$. You can check that $f(q_n)=g(q_n)$ for all $n$. Take $n\to\infty$.
Suppose $h(x) = f(x) – g(x)$. Then $h(x)$ is continuous and $h(x) = 0$ if $x \in \mathbb{Q}$. Let $\alpha$ be irrational. If $h(\alpha) > 0$ then since it is continuous there is a neighborhood $I$ of $\alpha$ in which $h(x)$ is positive. Clearly this neighborhood also includes rational numbers at which $h(x) = 0$. This contradiction shows that we can’t have $h(\alpha) > 0$. Similarly we can’t have $h(\alpha) < 0$. Thus $h(\alpha) = 0$. So $h(x) = 0$ for all $x$.
Different hint: Suppose there’s an irrational $a$ such that $f(a) \neq g(a)$. Can they still be continuous at that point?
Do you know that a function $h(x)$ is continuous at $x_0=a$ if and only if for every sequence $x_n\to a$ it holds that $f(x_n)\to f(a)$?
If so, use the fact that for all $x\in \mathbb{R}$ there exists a sequence $\{q_n\}\subset\mathbb{Q}$ such that $q_n\to x$.
Now combine those two things.