Inner loop on 2, outer loop on g.