Correct option is D
We use past perfect continuous for the earlier, longer action and simple past for the later action.
Hence:
"had been studying" … before "you arrived."
Grammatical rule used:
Use past perfect continuous (had been + verb-ing) for an action that was ongoing over a period before another past action.
The past perfect continuous shows duration and completion of an earlier past activity.
The simple past is used for the later action.
Example:
He had been working at the company for 10 years before he retired.
She had been reading all day before the guests came.
Information Booster:
If the action is interrupted or leads up to another specific past point, use past perfect continuous.
If you simply want to describe what was happening at a particular time in the past, use past continuous instead.