祖父 and 祖母: grandparents and generations
Introduce grandparents and use particles to identify who did what.
Introducing a grandfather
祖父 (そふ) means grandfather. 「祖父は山の近くに住んでいます」 says the speaker's grandfather lives near the mountains.
「母の父は私の祖父です」 identifies the mother's father as the speaker's grandfather. 祖父 alone does not specify the maternal or paternal side.
Introducing a grandmother
祖母 (そぼ) means grandmother. 「祖母に手紙を書きました」 means writing a letter to one's grandmother.
In 「祖母が手紙を書きました」, the grandmother wrote the letter. Replacing に with が changes her role.
Whose grandparents?
「友人の祖母に会いました」 says the speaker met a friend's grandmother. The person before の supplies the relationship's reference point.
「祖父母と一緒に食事をしました」 means having a meal with one's grandparents. 祖父母 is read そふぼ.
Did the grandmother write the letter in 「祖母に手紙を書きました」?
Show the answer and why
No. She is the recipient. 「祖母が手紙を書きました」 would make her the writer.

