One of the uses of past perfect is to refer to an event that takes place before another event in the past. For example:
I had written poetry before writing short stories.
PAST EVENT = writing short stories
PRIOR EVENT = I had written poetry
I didn't realize that you had written this until I read the comments.
PAST EVENT = I didn't realize
PRIOR EVENT = you had written this
I could understand the movie only because I had read the book before.
PAST EVENT = I could understand the movie
PRIOR EVENT = I had read the book
I wasn't surprised because I had prepared myself in advance.
PAST EVENT = I wasn't surprised
PRIOR EVENT = I had prepared myself
I had already left by the time you got home.
PAST EVENT = you got home
PRIOR EVENT = I had already left
I had already left when you got home.
PAST EVENT = you got home
PRIOR EVENT = I had already left
The last example above is similar to the one in your example:
- I had forgotten that I was going to read a book, when the guests came home and we started talking to each other.
PAST EVENT = the guests came home and we started talking to each other
PRIOR EVENT = I had forgotten that I was going to read a book
The event of "forgetting" takes places before the arrival of your guests, and the arrival of your guests happened some time in the past.
UPDATE
GregD points out in the comments that the situation described by the sentence:
I had forgotten that I was going to read a book, when the guests came home and we started talking to each other.
is unlikely. I agree with him and I think that a more plausible situation would be:
The guests came home and we started talking to each other, so I forgot that I was going to read a book.
In this case, GregD uses simple past to describe a sequence of events in the past. The order in which these events take place is inferred from the meaning of the sentence. It is also possible to use the past perfect to make apparent what this order is:
I forgot (simple past) that I was going to read a book, because the guests had come (past perfect) home and we had started (past perfect) talking to each other
In the first sentence you use a present participle: some people also call it an active participle. You use it to talking about something that you are doing.
I had been studying maths - I am doing the studying
The second sentence uses a past participle: some people call it a passive participle. You use it to talk about something that is being done to you.
I had been studied by scientists - the scientists are studying me
This is probably not the meaning that you intend, so let's rule out sentence 2.
Sentence 1 is past perfect continuous: it says that you were doing something for a period of time (three years) before some event in the past (reaching level B).
Sentence 3 is past simple: you did something for an unspecified period of time, and you completed it three years before you reached level B.
Sentence 1 is closer to what you probably meant, but there is no real need to use past perfect continuous: you could just change sentence 3 from simple past to past continuous and add a for:
I was studying for more than three years before I reached level B
Note that the to after reached is not required.
Best Answer
Keep It Simple - Stick to simple past.
Using past perfect (had come) places the narrative focus further back in time. Once you've started with that, you can't refer to anything earlier without also using past perfect, so OP's #1 is incorrect.
In this case, since studying predates coming to the factory, you could reasonably refer to the earlier action with past tense:
It would be (just about) possible to use had come in B. But it serves no purpose unless the narrative context primarily concerns other events in the past which are all later than both studying and coming to the factory. That's a complex literary context which probably isn't relevant here, so just forget about it.
If OP wants to use past continuous for the studying (I see no good reason for that here, and it seems "stilted" at best), I might prefer to see that same verb form reflected in the initial clause:
Note that A, B would be just as good with the "progressive/continuous" participle (coming), and C would be just as bad with simple past (he came). Although I must admit, "bad" is perhaps putting it too strongly; there are contexts where competent writers would use #3, but I don't think learners need concern themselves with this form until they've mastered the "standard" usages.