Democrats, Republicans reach deal to reopen government