Matrix queries getting TLE please help

i dont know why am getting tle
my code: https://ide.codingblocks.com/s/107665

question link
https://hack.codingblocks.com/contests/c/668/813

please see this qn
@Saurabh-Kumar-1331476656958199
bhaiya