Kie means "where" (static), kien means "to where" (destination). As explained in the notes of this section, adding -n to kie or tie shows a change of location. For example:
Kie vi estas? Mi estas ĉi tie.
Where are you? I am here.
(no -n because it's at a location)
Kien vi iras? Mi iras tien.
To where are you going? I am going to there.
(-n used because it's towards a location)
You never use the accusative -n ending after a preposition that already implies motion towards as 'al' does. There are some cases where you use the accusative after a preposition, e.g. 'mi kuras en la domo' - I am running in the house, versus 'mi kuras en la domon' - I am running into the house. In the former case I'm already in the house and am running around inside it; in the latter case the accusative implies motion towards, meaning I am running into the house from outside. But in the case of 'mi iras al lokon', the accusative is wrong because the 'al' already conveys the sense of motion towards the place. It should just be 'mi iras al loko'.
Yes, it specifies that there's a direction involved, but that's just an explanation to help us understand and learn the difference. The real reason why it carries the 'n' is because it's an object... well... like Samuel.Metcal said, because of both. When "where" means "to where" it specifies a direction and it's also an indirect object, since "to" is a preposition.
I can't believe Duo accepted "Whither goes Sofia?"! I was shocked when I submitted that translation of "Kien Sofia iras?" and it was accepted.
Nobody talks like that anymore. I know people who've never heard of hither, thither, whither, and yon(der), or hence, thence, and whence. I only used "whither" to see whether it would be marked wrong.
I should've written "Whither goeth Sofia?" Just for kicks & giggles!
Well, I am not a native speaker but i have been speaking and reading english for 20-30 years and NEVER came across "whither" and the likes (although I sometimes met "hence", and "whence").
So, imagine my surprise.
I heard and read more often "Where is Sofia going to ", "Where are you going to " and tought it was the right way to ask, since in german it would be "Wo gehst du hin " or in dutch "waar ga je naartoe ".
[EDIT] I did it again...
"Where is Sofia going to "
is accepted as a valid answer