Let $A$, $B$ be rings and $M$ be a $B$-module. Let $f:A \to B$ be a ring morphism. For a prime ideal $p \subset B$ let $q=f^{-1}(p)$, and the corresponding local morphism $A_q \to B_p$ makes $M_p$ an $A_q$-module.
I want to show: If for any prime ideal $p \subset B$, $M_p$ is a flat $A_q$-module, then $M$ is a flat $A$-module.
I want to use the fact "$M$ is flat over $A$ $\iff$ $M_q$ is flat over $A_q$ for all the primes $q \subset A$".
But I have difficulties in two places:
(1) In the above problem, I have $M_p$ rather than $M_q$, and it seems that they may not equal to each other.
(2) $q$ may not be chosen for all the primes in $A$.