Any or either of a group or set that….
"You may choose whichever book you prefer from the shelf."
Any one or a number of a group.
"Whichever books you choose from the shelf, we will read them all tonight."
Whichever comes from the combination of the words which and ever, both used in Middle English. It originally meant "no matter which one," combining a specific choice with an indefinite quantity to create its current meaning.