Because u are iterating till D which can be as big as 10^6 and the number of test cases is 10^5 so the total complexity will become 10^11 which is too much so u have to think of some mathematical solution that can be done in O(1) inside test case loop . Overall u r not allowed to iterate something in this test case because of high constraint.
Yes u r right but in such question they have mentioned like the size of tn would not exceed 10^5 or 6 like that. In this case they haven’t mentioned then u have to include t in your time complexity or not.
see this question in the constraints section last point they have mentioned that the Sum of N over all test cases does not exceed 210^5.