#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define s(x) scanf("%d", &x)
#define sd(x) scanf("%lf", &x)
#define sl(x) scanf("%lld", &x)
#define mod 1000000007
#define mod1 1000000006
#define get getchar//_unlocked
#define INF 1000000000000000000LL
ll a[2000005];
ll b[2000005];
ll prod[2000005];
ll power(ll a, ll b)
{
if (!b)
return 1;
ll x = power(a, b>>1);
if (b & 1)
return (((x*x)%mod)*a)%mod;
return (x*x)%mod;
}
int main()
{
ll i, type, d, k, n, m, tmpP;
a[0] = a[1] = b[0] = b[1] = 1;
prod[1] = 1;
for (i = 2; i <= 2000000; ++i) {
a[i] = (a[i-1] + (i+1)*a[i-2])%mod;
b[i] = (b[i-1] + i*b[i-2])%mod;
prod[i] = (prod[i-1]*i)%mod;
}
ll q, x, y, z, num, den,tmpN, tmpD;
cin >> q;
while (q--) {
cin >> type >> x >> y >> z;
z %= mod;
if (type == 1) {
if (x == 1)
num = z;
else
num = (((a[x-2] + z*b[x-1])%mod))%mod;
tmpP = (prod[y+1]*power(prod[x], mod-2))%mod;
num = (num * tmpP)%mod;
den = (a[y-1] + z*b[y])%mod;
// cout << num << " " << den << endl;
num = (num * power(den, mod-2))%mod;
cout << num << endl;
}
else {
num = 1;
den = 1;
for (k = 0; k <= y; ++k) {
n = x;
m = (z+k);
if (n == 1) {
tmpN = (m)%mod;
}
else {
tmpN = (((a[n-2] + m*b[n-1])%mod))%mod;
}
tmpP = (n+1);
num = (num * tmpP)%mod;
tmpD = (a[n-1] + m*b[n])%mod;
num = (num * tmpN)%mod;
den = (den * tmpD)%mod;
}
num = (num * power(den, mod-2))%mod;
cout << num << endl;
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBsbCBsb25nIGxvbmcgaW50CiNkZ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AgIGlmICh4ID09IDEpCiAgICAgICAgICAgICAgICBudW0gPSB6OwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBudW0gPSAoKChhW3gtMl0gKyB6KmJbeC0xXSklbW9kKSklbW9kOwogICAgICAgICAgICB0bXBQID0gKHByb2RbeSsxXSpwb3dlcihwcm9kW3hdLCBtb2QtMikpJW1vZDsKICAgICAgICAgICAgbnVtID0gKG51bSAqIHRtcFApJW1vZDsKICAgICAgICAgICAgZGVuID0gKGFbeS0xXSArIHoqYlt5XSklbW9kOwogICAgICAgICAgIC8vIGNvdXQgPDwgbnVtIDw8ICIgIiA8PCBkZW4gPDwgZW5kbDsKICAgICAgICAgICAgbnVtID0gKG51bSAqIHBvd2VyKGRlbiwgbW9kLTIpKSVtb2Q7CiAgICAgICAgICAgIGNvdXQgPDwgbnVtIDw8IGVuZGw7CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICBudW0gPSAxOwogICAgICAgICAgICBkZW4gPSAxOwogICAgICAgICAgICBmb3IgKGsgPSAwOyBrIDw9IHk7ICsraykgewogICAgICAgICAgICAgICAgbiA9IHg7CiAgICAgICAgICAgICAgICBtID0gKHorayk7CiAgICAgICAgICAgICAgICBpZiAobiA9PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgdG1wTiA9IChtKSVtb2Q7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgICAgICB0bXBOID0gKCgoYVtuLTJdICsgbSpiW24tMV0pJW1vZCkpJW1vZDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRtcFAgPSAobisxKTsKICAgICAgICAgICAgICAgIG51bSA9IChudW0gKiB0bXBQKSVtb2Q7CiAgICAgICAgICAgICAgICB0bXBEID0gKGFbbi0xXSArIG0qYltuXSklbW9kOwogICAgICAgICAgICAgICAgbnVtID0gKG51bSAqIHRtcE4pJW1vZDsKICAgICAgICAgICAgICAgIGRlbiA9IChkZW4gKiB0bXBEKSVtb2Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbnVtID0gKG51bSAqIHBvd2VyKGRlbiwgbW9kLTIpKSVtb2Q7CiAgICAgICAgICAgIGNvdXQgPDwgbnVtIDw8IGVuZGw7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0=
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/py_compile.py", line 117, in compile
raise py_exc
py_compile.PyCompileError: File "prog.py", line 3
using namespace std;
^
SyntaxError: invalid syntax