A. He came back to the city after an absence of 20 years.
Three question options:
A1. How long was his absence before he came to the city?
This doesn't sound right. The part that throws me off is the "before" section of the sentence. The fact that he was absent implies on its own that it was before. That contruction just doesn't sound very fluid.
I can be nitpicky sometimes, but I don't think that this is me being nitpicky - it just sounds like an awkward way of phrasing the question here.
Also, asking about the length of the absense in that way sounds a bit strange to me. It works technically, but I would prefer something different (see below).
A2. How long of an absence did he have before coming to the city?
This one is weird because of the first half. "How long of an absense did he have" is just not the way I would ask about the duration of an absense. See my version below.
A3. How long did his absence last before coming to the city?
This one is the better one of the three, but still is an awkward phrasing, likely due to the "before" part. An absense has to end with a return, so what's the point of saying "before coming to the city?"
If I had to ask about the length of his absense, I would ask like this:
How long was he absent (from the city) for?
Now, you may notice that I have a preposition at the end of my question. That seems to be said to be frowned upon, however, in all honesty, it's perfectly fine in conversation. The "fixed" version of the sentence to match what older people would say is wrong would be:
For how long was he absent (from the city)?
Either one works in my opinion, and nobody would bat an eye if you said the first one in conversation.
In both of these, the "from the city" is in parenthesis to denote that as optional - you don't really need it there.
A more conversational version would be:
How long was he gone for?
or the more stuffy version
For how long was he gone?
B. The drug was tested over a five-week period.
Three question options:
B1. How long was the period over which the drug was tested?
This one seems to correctly follow grammar rules. This is a good option.
B2. How long of a period was the drug tested over?
I think this one is correct as well. You likely could use "for" instead of "over" if you wanted. According to some, you shouldn't end a sentence with a preposition, but in reality (especially in conversation), this is totally fine.
B3. How long did the period last over which the drug was tested?
This is a very convoluted way of asking the question. I think it's correct, but I wouldn't use it. In programming, there is a term for this sort of case - "obfuscation."
There is just too much going on here. Stick with the previous two options.
My first choice for how to phrase this question would be:
How long was the drug tested for?
No need to even mention the period. Simply asking for the length indicates that you're asking about the period. It is a less "stuffy" way of asking.