> File Name: 5803.cpp
> Author: jiangyuzhu
> Mail: 834138558@qq.com
> Created Time: 2016/10/8 13:54:55
************************************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 18 + 5, mod = 1e9 + 7;
int dp[17][66][5][5];
int a[5][65];
int dfs(int pos, int s1, int s2, int top)
{
if(pos < 0){
return s1 > 0 && s2 >= 0;
}
if(dp[top][pos][s1 + 2][s2 + 2] != -1) return dp[top][pos][s1 + 2][s2 + 2];
int up[4];
for(int i = 0; i < 4; ++i){
up[i] = (top >> i & 1)?1:a[i][pos];
}
int ans = 0;
for(int a = 0; a <= up[0]; ++a){
for(int b = 0; b <= up[1]; ++b){
for(int c = 0; c <= up[2]; ++c){
for(int d = 0; d <= up[3]; ++d){
int ns1 = s1 * 2 + a + c - b - d;
int ns2 = s2 * 2 + a + d - b - c;
ns1 = min(ns1, 2);
ns2 = min(ns2, 2);
if(ns1 <= -2 || ns2 <= -2) continue;
int ntop = top;
if(a != up[0]) ntop |= 1 << 0;
if(b != up[1]) ntop |= 1 << 1;
if(c != up[2]) ntop |= 1 << 2;
if(d != up[3]) ntop |= 1 << 3;
(ans += dfs(pos - 1, ns1, ns2, ntop)) %= mod;
}
}
}
}
return dp[top][pos][s1 + 2][s2 + 2] = ans;
}
ll A, B, C, D;
int main (void)
{
int T;scanf("%d", &T);
while(T--){
memset(dp, -1, sizeof(dp));
scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
for(int i = 0; i <= 60; ++i){
a[0][i] = A >> i & 1;
a[1][i] = B >> i & 1;
a[2][i] = C >> i & 1;
a[3][i] = D >> i & 1;
}
printf("%d\n", dfs(60, 0, 0, 0));
}
return 0;
}