Why Does GROMACS Rename a DG Terminus to DG5 Without Manual Patching?

Hello,
I have a question about the terminal naming in the amber99bsc1 force field.
I checked the dna.rtp file, and it shows that the 5′ terminal is defined as DG5 and the 3′ terminal as DG3.
I renamed the terminal, and it worked—but I was surprised because it also works without renaming.
I believe it did not work in the past.
I tried to find the dna.tdb file in the Amber99bsc1 force field folder, but was unable to locate it.
I checked the topology, and both naming it ‘DG5’ and leaving it as ‘DG’ produce the same result.

It is not clear to me how GROMACS distinguishes the terminal residue when its name is the same as that of an internal nucleotide.
When I leave it as DG, GROMACS calculates the charge and writes DG5.
It is not clear to me how GROMACS understands that it is DG5. Does it distinguish this because DG appears on the first line of the file and follows TER?

When I leave it as DG
; nr type resnr residue atom cgnr charge mass typeB chargeB massB
; residue 1 DG rtp DG5 q -0.3
1 HO 1 DG H5T 1 0.4422 1.008
2 OH 1 DG O5’ 2 -0.6318 16
When I rename it:
; nr type resnr residue atom cgnr charge mass typeB chargeB massB
; residue 1 DG5 rtp DG5 q -0.3
1 HO 1 DG5 H5T 1 0.4422 1.008
2 OH 1 DG5 O5’ 2 -0.6318 16