On the $\ell$-adic Galois representations attached to nonsimple abelian varieties