Zotlin is an object-oriented programming language that provides features such as Classes and Functions. Zotlin also has the following features:
- A function with the same name and same declarations can have different implementations in different classes.
- Each class can inherit zero or more classes (excluding itself). If Class A inherits Class B, we say that Class A is a child of Class B.
- A class cannot inherit another class if a cycle is formed by inheritance.
For example, if Class A inherits Class B and Class B inherits Class C, then Class C cannot inherit Class A.
A Class X is called an ancestor of Class Y, if Y inherits directly or indirectly from Class X. ie, say Class Y inherits from Class Z, which inherits from Class X. Then Class X is an ancestor of both Class Y and Class Z.
Mr. Zourist — a very popular programmer — wrote a program in Zotlin with N classes numbered from 1 to N. Some of these classes have an implementation of a function F. The Zotlin compiler needs to determine which definition of function F should be called for an object of Class 1.
In order to deterministically decide which implementation of function F to use, the compiler uses a list called the Resolution Order (RO list). This is a list containing Class 1 and its ancestors. The compiler iterates through this list to search for a class that contains an implementation of function F.
The properties of an RO list are as follows:
- The 1st member of the list is Class 1.
- The list contains only the ancestors of Class 1. All the Classes in the list are unique.
- It is guaranteed that no Class occurs after any of its ancestors in the list.
Let's define the Special RO list as an RO list of length N where the ith member in the list is Class i. That is, the Special RO list is [1, 2, 3, ... , N].
Find out the number of distinct class-inheritance hierarchies Mr. Zourist could have created in his program for which one of the valid RO lists is the Special RO list. Print your output modulo 109 + 7.
Two class-inheritance hierarchies are considered different if they have at least one class that inherits a different list of classes.
Input
The first line of input contains a positive integer T - denoting the total number of testcases.
T lines follow - the ith line contains a single positive integer N- denoting the number of classes written by Mr. Zourist.
Output
For each testcase, print the required number of distinct class-inheritance hierarchies modulo 109 + 7 on a new line.
Constraints
- 1 ≤ T ≤ 105
- 1 ≤ N ≤ 105
Example
Input
2 3 6 Output 3 9765
Explanation
Explanation for testcase 1:
Let "class X" denote that X does not inherit any class
Let "class X(Y)" denote that X inherits Y
Let "class X(Y, Z)" denote that X inherits Y, Z
First possibility:
class 2 class 3 class 1(2, 3)
Second possibility:
class 3 class 1(2) class 2(3)
Third possibility:
class 3 class 1(2, 3) class 2(3)
These are the three valid class-inheritance hierarchies, and hence the answer is 3.
Note that the following hierarchy is not valid:
class 1(2) class 2 class 3
This is because 3 should have been an ancestor of 1, but in the above hierarchy, 3 is a stand-alone class.
#include <iostream>
#include <cstdio>
using namespace std;
const int inf=1e9+7;
long long ksm(int n)
{
long long a=2,b=1;
while(n)
{
if(n%2)
{
b*=a;
b%=inf;
}
a*=a;
a%=inf;
n/=2;
}
return b-1;
}
int main()
{
int t,n,i;
long long a[100050];
a[1]=1;
for(int i=2; i<=100000; i++)
{
a[i]=a[i-1]*ksm(i-1);
a[i]%=inf;
}
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%lld\n",a[n]);
}
return 0;
}