Q:

Base change and affine maps

I'm stuck at the sentence "The morphism $(1,g): X \mapsto X \times_S Y$ is the base change of $Y \mapsto Y \times_S Y$ by the morphism $X \times_S Y \mapsto Y \times_S Y$." Why is that? If I call $X \times_S Y = T, \ Y \times_S Y = T'$ then I'd have to show that
$$X = Y \times_T T', \ X \times_S Y = (Y \times_S Y) \times_T T'.$$
I think I figured out the second equality, but I'm stuck on the first one. Can someone help?

A:

Let us show the universality property. Unfortunately, i cannot draw here diagrams as i want, so please rotate the diagram below.
We start with some scheme $Z$ and two morphisms that fit in the diagram:
$\require{AMScd}$
\begin{CD}
Y @<h<< Z \\
@V (1,1) V V   @V V k V \\
Y\times_S Y @<{g\times_S 1}<< X\times_S Y \\
@V{\pi_1} VV  @VV{\pi_1} V\\
Y @<<g< X
\end{CD}
This gives us a morphism from $Z$ to $X$ given by composing the two vertical arrows $Z\to X\times_SY$ and the projection $\pi_1$ from the last object on its first factor. We then want to show the commutativity of the diagram 
$\require{AMScd}$
\begin{CD}
Z @= Z @=Z \\
@V h V V   @. \swarrow{\pi_1k} @| \\
Y @<g<< X @. Z\\
@V (1,1) V V   @V V (1,g) V @|\\
Y\times_S Y @<{g\times_S 1}<< X\times_S Y @<k<< Z\\
\end{CD}
This follows from 
$$
\begin{aligned}
g\circ \pi_1 k &=
\pi_1(1,1)\circ h
\\
&=1\circ h
\\
&=h\ ,
\\[3mm]
(1,g)\circ \pi_1 k
&=(1,g) \pi_1 \circ k
\\
&=1 \circ k
\\
&=k
\ .
\end{aligned}
$$
For the uniqueness of the morphism from $Z$ to $X$, consider some factorizing map $f$ in the diagram above in the place of $\pi_1 k$, and in the relation $(1,g)f=k$ precompose with the projection $\pi_1$ on $X$ (as in the first commutative diagram).

