


The first line of input contains an integer 'T' denoting the number of test cases.
The first line of each test case contains an integer 'N', the size of the permutation.
For each test case, print the total number of derangements of a set of n elements.
The output of each test case will be printed in a separate line.
The ‘answer’ could be very large, thus output ‘answer’ % (10 ^ 9 + 7).
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 5*10^3
Time Limit: 1 sec
We are solving this problem by solving its subproblems and then combining the solutions of those subproblems. If we analyze carefully, we will see that we are solving the same subproblems multiple times. Thus, this problem exhibits overlapping subproblems. Thus, in this approach, we will eliminate the need to solve the same subproblems repeatedly.
Here is the algorithm:
We are solving this problem by solving its subproblems and then combining the solutions of those subproblems. If we analyze carefully, we will see that we are solving the same subproblems multiple times. Thus, this problem exhibits overlapping subproblems. Thus, in this approach, we will eliminate the need to solve the same subproblems repeatedly.
Here is the algorithm: