for i in range(int(input())):
n,m=map(int,input().split())
dp=[0]*(n+1)
mod=1000000007
for i in range(1,n+1):
if i>m:
dp[i]=(dp[i-1]+dp[i-m])%mod
elif i<m:
dp[i]=1
else:
dp[i]=2
print(dp[n]%mod)
Why this is showing error on test case 2 and 4?
Error in test case 2 and 4
Your logic for solving this problem is correct, but you are getting TLE in test case 2 and 4 because python is a slow languages and it is possible that time constraints for this questions havent been adjusted properly for that. try solving this question in C++