She composed an elegy for her departed friend.
A dirge was played at the funeral.
哀歌 is a broader term for a sad song or lament, not necessarily for the dead.
Compound of 哀傷 (grief, sorrow) and 歌 (song). The exact historical derivation is uncertain, but the term is conventionally associated with classical Japanese poetry and mourning rituals.