Telefonica turns profitable as revenues shrink