I'm a bit biased, of course, but I'd say Montreal as well. You'll have close to a full day in the city, and summer is
peak festival season. Montreal is much less spread out than Toronto, and it's easier to see things in a few hours.
Just one note: You'll be arriving and departing at rush hour. In summer, the traffic volumes are a little lighter, but that's counteracted by our infamous amount of construction. You can get the 747 bus from the airport to Lionel-Groulx metro station or to downtown, which takes about 20 minutes with no traffic... but you should expect traffic. That might cut back on your time to explore a little bit. Taxis aren't really much faster, as they have to sit in the same traffic as the bus. At best, you can figure on getting into the city by 10 or so, maybe longer if you don't have Global Entry since you'll have to clear Canadian customs on arrival in YUL. For a 4:40pm departure on a weekday, you need to leave for the airport by 2pm or so. So you'll have a few hours to quickly walk around, get some lunch, see a few things.
Any chance of extending the layover into a legitimate overnight stopover, and giving yourself ~32 hours instead of 8?