We discuss the ℓ-adic case of Mazur's "Program B" over Q, the problem of classifying the possible images H ≤ GL 2 (Z ℓ ) of Galois representations attached to elliptic curves E over Q, equivalently, classifying the rational points on the corresponding modular curves X H . The primes ℓ = 2 and ℓ ≥ 13 are addressed by prior work, so we focus on the remaining primes ℓ = 3, 5, 7, 11. For each of these ℓ, we compute the directed graph of arithmetically maximal ℓ-power level modular curves, compute explicit equations for most of them, and classify the rational points on all of them except X + ns (N ), for N = 27, 25, 49, 121, and two level 49 curves of genus 9 whose Jacobians have analytic rank 9.Aside from the subgroups of GL 2 (Z ℓ ) known to arise for infinitely many Q-isomorphism classes of elliptic curves E/Q, we find only 22 exceptional subgroups that arise for any prime ℓ and any E/Q without complex multiplication; these exceptional subgroups are realized by 20 non-CM rational j-invariants. We conjecture that this list of 22 exceptional subgroups is complete and show that any counterexamples must arise from unexpected rational points on X + ns (ℓ) with ℓ ≥ 17, or one of the six modular curves noted above. This gives us an efficient algorithm to compute the ℓ-adic image of Galois for any non-CM elliptic curve over Q.In an appendix with John Voight we generalize Ribet's observation that simple abelian varieties attached to newforms on Γ 1 (N ) are of GL 2 -type; this extends Kolyvagin's theorem that analytic rank zero implies algebraic rank zero to isogeny factors of the Jacobian of X H .