Showing two ring homomorphisms that agree on the integers must agree on the rationals 
I have two ring homomorphisms $f,g\colon \mathbb{Q}\to X$. I know that $f=g$ on the integers. How can I show that $f$ and $g$ agree on the rationals?

My attempt:
let $x,y \in \mathbb{Z}$, $y\neq 0$. 
$$\begin{align*}
f(x/y)&=f(x)f(1/y) &&\text{because }f\text{ is a ring homomorphism}\\
 &=g(x)f(1/y) &&\text{because }f\text{ and }g\text{ agree on the integers}
\end{align*}$$
I do not know how to rewrite $f(1/y)$ so that I can replace it with $g(1/y)$. Any hints will be much appreciated. Thanks. 

This can be done by using a "zig-zag": 
$$\begin{align*}
f\left(\frac{x}{y}\right) &= f\left(\frac{1}{y}\cdot x\right)\\
&= f\left(\frac{1}{y}\right)\cdot f(x)\\
&= f\left(\frac{1}{y}\right)\cdot g(x)\\
&= f\left(\frac{1}{y}\right)\cdot g\left(xy\cdot \frac{1}{y}\right)\\
&= f\left(\frac{1}{y}\right)\cdot g(xy)\cdot g\left(\frac{1}{y}\right)\\
&= f\left(\frac{1}{y}\right)\cdot f(xy)\cdot g\left(\frac{1}{y}\right)\\
&= f\left(\frac{1}{y}\cdot xy\right)\cdot g\left(\frac{1}{y}\right)\\
&= f(x)\cdot g\left(\frac{1}{y}\right)\\
&= g(x)\cdot g\left(\frac{1}{y}\right)\\
&= g\left(x \cdot \frac{1}{y}\right)\\
&= g\left(\frac{x}{y}\right).
\end{align*}$$
This proves, by the by, that the embedding $\mathbb{Z}\hookrightarrow\mathbb{Q}$ is a (non-surjective) epimorphism in the category of rings. The argument does not require $X$ to have a unit, or for homomorphisms to map the unity of $\mathbb{Q}$ to the unity of $X$ even when $X$ does have a unity. 

Added. In fact, the argument does not even need $f$ and $g$ to be ring homomorphisms, only to be (multiplicative) semigroup homomorphisms. So $(\mathbb{Z},\cdot)\hookrightarrow (\mathbb{Q},\cdot)$ is an epimorphism in the category of semigroups.
The zig-zag is actually part of the characterization of when two semigroup homomorphisms that agree on a subsemigroup agree on an element:

Isbell's Zigzag Theorem for Semigroups
Let $S$ be a semigroup, $D$ a subsemigroup of $S$. Every pair of semigroup homomorphism with domain $S$ and common codomain that agree on $D$ agree on $s$ if and only if $s\in D$, or there is a sequence of factorizations of $s$ of the form
  $$s=a_1d_1=a_1e_1b_1 = a_2d_2b_1 = a_2e_2b_2 = \cdots = a_{n-1}d_{n-1}b_{n-1}=a_nb_{n-1},$$
  where $d_i,e_j\in D$, $a_k,b_{\ell}\in S$, and $d_1=e_1b_1$, $a_{n-1}d_{n-1}=a_n$, and
  $$a_ie_i = a_{i+1}d_{i+1},\quad d_{i+1}b_i = e_{i+1}b_{i+1},\qquad\text{for }i=2,3,\ldots,n-2.$$

One direction (from the "zigzag" equations to the fact that $f$ and $g$ agree) is easy. There is a nice proof of the other direction in A short proof of Isbell's Zigzag Theorem by P. M. Higgins, Pacific Journal of Mathematics 144 no. 1 (1990), pages 47-50. 
The collection
$$\bigl\{ s\in S\mid \forall T\;\forall f,g\colon S\to T\ ( f|_D=g|_D\rightarrow f(s)=g(s)\;)\bigr\}$$
is called "the dominion of $D$ in $S$". It can be defined for any category of algebras, though in many standard categories the dominion of a subalgebra is always equal to the subalgebra itself. 
The basic reference is the sequence of papers by John Isbell:


*

*J.R. Isbell, Epimorphisms and dominions. 1966 Proc. Conf. Categorical Algebra (La Jolla, Calif., 1965) pp 232-246; Springer-Verlag, MR0209202 (35 #105a) (Note: the statement of the zigzag lemma for rings in this paper is incorrect; the correction appears in a later paper).

*J.R. Isbell and John M. Howie, Epimorphisms and dominions, II. J. Algebra 6 (1967), pp. 7-21, MR0209203 (35 #105b)

*J.R. Isbell, Epimorphisms and dominions, III. Amer. J. Math. 90 (1968), pp. 1025-1030, MR0237596 (38 #5877)

*J.R. Isbell, Epimorphisms and dominions, IV. J. London Math. Soc. Ser. 2 1 (1969), pp. 265-273, MR0257120 (41 #1774)

*J.R. Isbell, Epimorphisms and dominions V. Algebra Universalis 3 (1973), pp. 318-320, MR0349536 (50 #2029)
There is also a nice survey by Peter M. Higgins, Epimorphisms and Amalgams, Colloq. Math. 56 (1988) no. 1, pp. 1-17, MR0980507 (89m:20083). 
