I want to show that $\mathbb{A}_B^n=\mathbb{A}_\mathbb{Z}^n\times_{\mbox{Spec }\mathbb{Z}}B$ for every ring $B$, where $\mathbb{A}_B^n:=\mbox{Spec }B[x_1,\ldots,x_n]$. This is equivalent to showing that $\mathbb{A}_B^n$ possesses the universal property that the product has, and so if I have a scheme $X$ and morphisms $g:X\to\mbox{Spec }B$ and $h:X\to\mbox{Spec }\mathbb{Z}[x_1,\ldots,x_n]$ that commute with the morphisms from these affine schemes to $\mbox{Spec }\mathbb{Z}$, then I get a unique morphism from $X$ to $\mathbb{A}_B^n$.
Writing out everything properly, this basically comes down to the following problem: given $p\in\mbox{Spec }\mathbb{Z}[x_1,\ldots,x_n]$ and $q\in\mbox{Spec }B$ with the property that $p\cap\mathbb{Z}=\varphi^{-1}(q)$ (where $\varphi:\mathbb{Z}\to B$ is the natural homomorphism), then there exists an ideal $r\in\mbox{Spec }B[x_1,\ldots,x_n]$ such that $r\cap B=q$ and $\hat{\varphi}^{-1}(r)=p$ (where $\hat{\varphi}:\mathbb{Z}[x_1,\ldots,x_n]\to B[x_1,\ldots,x_n]$ is the morphism induced by $\varphi$).
Any ideas? Am I just missing something? Is there another easier way to tackle this exercise?