God is real . . . unless declared integer
FORTRAN IV (Compiled with gfortran -ffixed-form), 309 291 290 280 398 393 392 334 237 231 bytes + Bonus imaginary Internet points



This should now be a proper FORTRAN IV program, with no anachronisms!



&#9;REALS(200)
&#9;DATAG,R,H,A/1HG,1HR,1H-,1H(/
&#9;READ 9,S
    9&#9;FORMAT(200A1)
&#9;DO1 I=1,200
&#9;C=S(I)
&#9;IF(C.NE.A)GOTO2
&#9;T=S(I-1)
&#9;GOTO1
    2&#9;IF(C.LT.G.AND.S(I+1).EQ.H.AND.S(I+2).GE.G.OR.C.EQ.G)GOTO8
    1&#9;CONTINUE
&#9;T=R
    8&#9;PRINT 9,T
&#9;END


Try it online!

Here's the same code embedded in a loop that runs through the entire test suite.  I don't think this can be done with TIO's header and footer.



18 bytes off thanks to @JonathanAllan, who pointed out that one IF statement wasn't needed.

1 more byte off by eliminating a stray space between CHARACTER and S at the top.

And 10 more bytes by rearranging the spaghetti code a bit.

Added 118 bytes to put it in proper FORTRAN IV fixed-column punch-card formatting. (This is for historical accuracy -- it isn't necessary for proper functioning under gfortran.)

Shaved off 5 more bytes: Cleaned up the GOTOs a bit, and changed the treatment of characters so it's actually correct for FORTRAN IV.

1 more byte off from removing an unneeded space in the DATA statement.

58 bytes off by streamlining the flow of control through the various IF statements.

97 more bytes off by: (1) eliminating variable P; and (2) replacing the spaces required at the beginning of a line with a tab character, which I found is allowed, according to an old FORTRAN IV manual. (I was thinking of punch card machines, which, as I recall, didn't have a horizontal tab, but I forgot about teletype machines, which did have a tab key.)

Thanks to @Dingus for 6 more bytes (from removing the B in the DATA statement which was no longer needed after P was eliminated).



I've limited myself to FORTRAN IV constructs here.  This should now be a correct FORTRAN IV program, without such things as the CHARACTER data type and quote-delimited strings, which were only introduced later.  

Characters in FORTRAN IV needed to be entered as Hollerith constants, and they could be stored in variables of type REAL (and probably other types sometimes too, but there was no CHARACTER type originally).  (As I recall, a real could hold 5 ASCII characters from what we now call a string.  I think they were padded with spaces if there were fewer than 5 characters in a grouping.  The single characters I use are each stored as a real, padded with extra space characters in the real.)

Input is on stdin, on one line, just like the OP's test cases.

Output is on stdout.



FORTRAN IV was my introduction to computer programming -- it was the first programming language I ever learned.  When I was a boy, I read through my dad's textbooks when he took a class in it at NYU, which was required by his musicology graduate program.  Computer programming (as well as FORTRAN itself) has changed quite a bit since then :) .