If Q is a factor of 18 and T is prime numbers between 2 and…