Let a be the primitive root and n be the modulus. Party A secret be KA and let party B secret be KB.
Party A is aware of a,n and KA whereas Party B is aware of a,n and KB. Message sent by A to B will be Mab = aKA mod n and message sent by party B to A will be Mba = aKB mod n
Mab = 38 mod 47
Mba = 310 mod 47
The DH key for party A will be (Mba)8 mod 47 which is equal to DH key for party B which is, (Mab)10 mod 47.
(Mba)8 mod 47 = (Mab)10 mod 47 = (310 mod 47)8 mod 47 = (38 mod 47 )10 mod 47 = 380 mod 47 = 4