I am trying to achieve the following in LaTeX:

It's always some part of the word that has to be underlined, or overlined. the underlined/overlined length in characters always differs.
I'd like to type something like:
g\LOWERLINE{aa}tum y\LOWERLINE{a}jnaay\UPPERLINE{a}...
Can't figure out how to get this working.
Thanks in advance