#include #include #include #include #include #include using namespace std; typedef long long LL; typedef vector VI; #define REP(i,n) for(int i=0, i##_len=(n); i inline void amin(T &a, const T &b) { if (b inline void amax(T &a, const T &b) { if (a struct ModInt { unsigned x; void undef() { x = (unsigned)-1; } bool isnan() const { return x == (unsigned)-1; } inline int getInt() const { return (int)x; } template T get() const { return (T)x; } inline int mod() const { return MOD; } ModInt(int y=0) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; } ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; } ModInt(unsigned long long y) { if (MOD<=y) x = y % (unsigned long long)MOD; else x = y; } ModInt &operator+=(const ModInt &y) { if ((x += y.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(const ModInt &y) { if ((x += MOD - y.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(const ModInt &y) { x = (unsigned long long)x * y.x % (unsigned long long)MOD; return *this; } ModInt &operator/=(const ModInt &y) { x = (unsigned long long)x * y.inv().x % (unsigned long long)MOD; return *this; } ModInt operator-() const { return (x ? MOD-x: 0); } ModInt inv() const { unsigned a = MOD, b = x; int u = 0, v = 1; while (b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if (u < 0) u += MOD; return ModInt(u); } ModInt pow(long long y) const { ModInt b = *this, r = 1; if (y < 0) { b = b.inv(); y = -y; } for (; y; y>>=1) { if (y&1) r *= b; b *= b; } return r; } }; const LL MOD = 1000000007; typedef ModInt Mint; Mint operator+(Mint x, const Mint &y) { if ((x.x += y.x) >= (unsigned)x.mod()) x.x -= x.mod(); return x; } Mint operator-(Mint x, const Mint &y) { if ((x.x += x.mod() - y.x) >= (unsigned)x.mod()) x.x -= x.mod(); return x; } Mint operator*(Mint x, const Mint &y) { x.x = (unsigned long long)x.x * y.x % (unsigned long long)x.mod(); return x; } Mint operator/(Mint x, const Mint &y) { x.x = (unsigned long long)x.x * y.inv().x % (unsigned long long)x.mod(); return x; } bool operator<(const Mint &x, const Mint &y) { return x.x < y.x; } bool operator==(const Mint &x, const Mint &y) { return x.x == y.x; } bool operator!=(const Mint &x, const Mint &y) { return x.x != y.x; } LL l, r, g, t; char L[100], R[100], G[100], T[100]; Mint dp[101][16]; void bit(char X[], LL x) { for (int i=80; i--;) { X[i] = x&1; x>>=1; } } void MAIN() { scanf("%lld%lld%lld%lld", &l, &r, &g, &t); memset(dp, 0, sizeof dp); dp[0][0] = 1; bit(L, l); bit(R, r); bit(G, g); bit(T, t); REP (i, 80) REP (s, 16) REP (c, 2) { if (~s&1 && (G[i]^c) < L[i]) continue; if (~s&2 && (G[i]^c) > R[i]) continue; if (~s&4 && (T[i]^c) < L[i]) continue; if (~s&8 && (T[i]^c) > R[i]) continue; int ns = 0; if (s&1 || (G[i]^c) > L[i]) ns |= 1; if (s&2 || (G[i]^c) < R[i]) ns |= 2; if (s&4 || (T[i]^c) > L[i]) ns |= 4; if (s&8 || (T[i]^c) < R[i]) ns |= 8; dp[i+1][ns] += dp[i][s]; } Mint same = 0; REP (s, 16) same += dp[80][s]; Mint ans = Mint(2)*(r-l+1) - same; printf("%d\n", ans.getInt()); } int main() { int T; scanf("%d", &T); REP (i, T) MAIN(); return 0; }