Normally the preposition a is used to mark an indirect pronoun (Do il libro a Luigi <=> I give Luigi the book). But in this case (Penso a lui <=> I think of him) the preposition is required by the verb pensare and has nothing to do with an indirect object. The case of scrivere is different. In this case we have a really indirect object because this verb can have a direct object as well (I write her a letter) and so the remaining object only can be a direct object.
A chi scrivi (questa lettera)?
<=> To whom do you write the letter?
In the case that the verb can only add one object this object is, apart from some few exceptions, a direct object.
L' aiuto a fare i suoi compiti.
<=> I help him to do his homework.
And if we ask for this object we use chi.
Chi aiutiamo? <=> Who do you help?
Because of the fact that chi can ask for the subject of the sentence and for the indirect object as well this sentence is ambiguous.
Chi aiuta? <=> Who helps? / Whom does he help?
Che and quale
Che means what and quale means which. Sometimes what / che can be substituted by which / quale the difference is not always very clear.
What river flows through London?
Which river flows through London?
Nevertheless there is a difference. We use what / che if we ask for a characteristic of something and which / quale if we ask for an element of a group with similar elements.
a) Which cake do you want?
b) What cake do you want?
The context in which these questions are used is different. In case a) we are in a pastry shop and we have to select between several cakes in the display cabinet. We don't ask for characteristics, we ask for an element of a group. In case b) we are asked to give a description of the cake (chocolate, fruit, marzipan, whipping cream, etc.). In some contexts which can't be substituted by what.
a) correct: Which book by Joseph Conrad is your favourite?
b) wrong: What book by Joseph Conrad is your favourite?
If it is evident that we ask for a specific element of a group and not for the charactiristics of something we must use which / quale. In case a) we ask for a specific element and therefore b) is wrong. But if we ask for certain characteristics of something we must use what / che.
a) correct: What kind of type he is?
b) wrong: Which kind of type he is?
In this case the situation is completely different. We don't ask for an element of a group, but for some characteristics (intelligent, handsome, nice, etc.). Sometimes what / che as well as which/ quale can be used, but this substitution is not possible, if the context refers to an element or to characteristics.
If there is a group of reference what / che can' t be used.
The reference group is explicetly mentioned, che is not possible
correct: Di tutte le lettere che hai ricevuto, qual è la più bella?.
correct: Di tutte le lettere che hai ricevuto, che è la più bella.
Out of all the letters you got, which one you is the prettiest?
The question is actually about an element, but the reference group is not explicetely mentionned
correct: Quale treno devo prendere?
correct: Che treno devo prendere?
correct: Which train should I take?
What train should I take?
As a rule of thumb one could say that which / quale is to be used if the group of reference is mentioned and what / che is to be used if there is no group at all. In all the cases between these extremes what / che can be substituted by which / quale and vice versa.
a) Quale fiore ti piace?
=> Which flowers do you like?
b) Che fiore ti piace?
=> What flowers do you like?
If someone is asked what kind of flowers he likes, in general, then the correct form would be b). But if he asked this question in a flower shop and he is asked to choose between a group of flowers a) would be the more appropriate question.
a) wrong: Quale opinione si è fatto?
b) correct: Che opinione si è fatto?
=> What' s your opinion about that?
In this case there is no ambiguity and the sentence is independent from any context. There is no reference group of opinions where he can choose one, he only has one single opinion and he is only asked to describe it.
The situation is a little bit clearer if which / quale and what / che are used as pronouns. Used as a pronoun quale / which can't be used to ask for characteristics and che / what used as a pronoun cannot be used to ask for an element of a group. Used as pronouns which / quale suggest that there is a reference group and the question is about an element of this group. Used as pronouns the difference between which / quale and what / che is much clearer than the difference between the adjectives which / quale <=> what / che.
a) Con che cosa pulisco il motore?
With what can I clean the engine?
b) Con quale pulisco il motore?
With which can I clean the engine?
In case a)
we don' t ask for an element, the question is absolute. In case b) we have for instance several cleaning clothes and the question is which one to use.