1. Tom built a house which is on the hill.

2. Tom built the house which is on the hill.
[Are both grammatical? Is there any difference because of 'a' and 'the'?]

In 1, there are two or more houses on the hill; Tom built one of them.

In 2, there is only one house on the hill; Tom built it.