Facto sum, getting WA

how to solve this? WA for some test cases
https://ide.codingblocks.com/#/s/21938

https://online.codingblocks.com/player/5104/content/786?s=630

https://ide.codingblocks.com/#/s/22114
try this and in these cases try to take mod whereever you can it shortens your no. at every step