#include <bits/stdc++.h>
using namespace std;
const int MAXP = 25;
const int MOD = 1000000007;
int DP[1 + MAXP];
int main()
{
DP[0] = 1;
for (int i = 1; i <= MAXP; ++i) {
for (int j = 1; j <= 3; ++j) {
if (j <= i) {
DP[i] = (DP[i] + DP[i - j]) % MOD;
}
}
}
int t;
cin >> t;
while (t--) {
long long a = 1;
for (int i = 0; i < 4; ++i) {
int p;
cin >> p;
a = (a * DP[p]) % MOD;
}
cout << a << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTUFYUCA9IDI1Owpjb25zdCBpbnQgTU9EID0gMTAwMDAwMDAwNzsKCmludCBEUFsxICsgTUFYUF07CgppbnQgbWFpbigpCnsKICAgIERQWzBdID0gMTsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IE1BWFA7ICsraSkgewogICAgICAgIGZvciAoaW50IGogPSAxOyBqIDw9IDM7ICsraikgewogICAgICAgICAgICBpZiAoaiA8PSBpKSB7CiAgICAgICAgICAgICAgICBEUFtpXSA9IChEUFtpXSArIERQW2kgLSBqXSkgJSBNT0Q7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBpbnQgdDsKICAgIGNpbiA+PiB0OwogICAgd2hpbGUgKHQtLSkgewogICAgICAgIGxvbmcgbG9uZyBhID0gMTsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IDQ7ICsraSkgewogICAgICAgICAgICBpbnQgcDsKICAgICAgICAgICAgY2luID4+IHA7CiAgICAgICAgICAgIGEgPSAoYSAqIERQW3BdKSAlIE1PRDsKICAgICAgICB9CiAgICAgICAgY291dCA8PCBhIDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==