Let $A$ and $B$ be finitely generated $\mathbf{Z}$-algebra. Suppose that there exists two coprime integers $m$ and $n$ and an isomorphism of $\mathbf{Z}$-algebra $\phi:A\otimes_{\mathbf{Z}}\mathbf{Z}[1/n]\simeq B\otimes_{\mathbf{Z}}\mathbf{Z}[1/m] $. Then we can glue $A$ and $B$ along $\phi$ so that we obtain a scheme $Y$ over $Spec(\mathbf{Z})$.
Q1: Under what general conditions do we have $Y$ affine ?
Q2: In the case where $Y=Spec(C)$ is affine then how do we construct the $\mathbf{Z}$-algebra $C$ from the triple $(A,B,\phi)$?