Nasdaq records best quarterly gain since 2020 as US exchanges post monthly gains