In principle I agree with what TraceyG says. If it is a general question, use ‘what.’ If there is a preference or choice given or you want to elicit a specific response, use ‘which.’
But in practice, it is not so simple.
If someone asks, “What floor do you live on?” they are eliciting a specific response: on which floor? Which floor do you live on?
Likewise, if someone asks, “What grade are you in?” they are eliciting a specific response: in which grade? Which grade are you in?
So how do you know when to use ‘which’ and when to use ‘what’? That is a simple question to a more complex answer.
I would just note that in both cases a preposition is used: to live on a certain floor; to be in a certain grade.
In most cases, when the question is about ‘which’ specific setting or location: from which country, in which city, at which store, to which school, in which grade, on which floor, etc., so that it ends in a preposition, either ‘which’ or ‘what’ is acceptable, there is no difference in the type of response that is being elicited, yet I would say that most people prefer to use ‘what.’
All of the following questions can use ‘which,’ but I would say that ‘what’ is preferred:
I’m from Taiwan. What country are you from?
I live in Taipei. What city do you live in?
I shop at Breeze Super. What store do you shop at?
My daughter goes to Nei-Hu. What school do you go to?
My son is in the sixth grade. What grade are you in?
I live on the fifth floor. What floor do you live on?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
side note:
Just as a point of comparison, I would like to point out that the Dutch always use welk/welke (which) in these types of questions:
Uit welke land kom jij? From which country do you come?
In welke stad woon jij? In which city do you live?
Bij welke winkel doe jij je boodschappen? At which store do you shop?
Op welke school zit jij? At which school do you sit?
In welke klas zit jij? In which grade do you sit?
Op welke verdieping woon je? On which floor do you live?