Fix off-by-one error in trimming queues

Change-Id: Ibf602466ecf951d745c396ff47b067cce94044bd