Mr. Chanek just won the national chess tournament and got a huge chessboard of size $$$N \times M$$$. Bored with playing conventional chess, Mr. Chanek now defines a function $$$F(X, Y)$$$, which denotes the minimum number of moves to move a knight from square $$$(1, 1)$$$ to square $$$(X, Y)$$$. It turns out finding $$$F(X, Y)$$$ is too simple, so Mr. Chanek defines:$$$G(X, Y) = \sum_{i=X}^{N} \sum_{j=Y}^{M} F(i, j)$$$Given X and Y, you are tasked to find $$$G(X, Y)$$$.A knight can move from square $$$(a, b)$$$ to square $$$(a', b')$$$ if and only if $$$|a - a'| > 0$$$, $$$|b - b'| > 0$$$, and $$$|a - a'| + |b - b'| = 3$$$. Of course, the knight cannot leave the chessboard.

The first line contains an integer $$$T$$$ $$$(1 \le T \le 100)$$$, the number of test cases. Each test case contains a line with four integers $$$X$$$ $$$Y$$$ $$$N$$$ $$$M$$$ $$$(3 \leq X \leq N \leq 10^9, 3 \leq Y \leq M \leq 10^9)$$$.

For each test case, print a line with the value of $$$G(X, Y)$$$ modulo $$$10^9 + 7$$$.

#include <cstdio>
const int MOD = 1000000007,
          inv2 = (MOD+1)/2,
          inv3 = (MOD+1)/3,
          inv4 = (MOD+1)/4,
          inv6 = (MOD+1)/6,
          inv72 = (MOD+1)/72;
const int magic3[3] = {0, -32, -16},
          magic6[6] = {-16, 36, -32, 20, 0, 4};

int _add(int x) { return x < MOD ? x : x - MOD; }
int add(int x, int y) { return _add(x + y); }
int _sub(int x) { return x < 0 ? x + MOD : x; }
int sub(int x, int y) { return _sub(x - y); }
int mul(int x, int y) { return 1LL * x * y % MOD; }

int f4(int x)
{
    int res = mul(x + 6, mul(x, x));
    if (x % 2 == 0)
        res = add(res, MOD + magic3[x / 2 % 3]);
    else
        res = add(res, add(mul(9, x), MOD + magic6[(x - 1) / 2 % 6]));
    res = mul(inv72, res);
    return res;
}

int f3(int x, int y)
{
    int res = mul(inv6, mul(add(x, y) + 4, mul(x + 1, y + 1)));
    if (x % 3 + y % 3 < 2)
        res = sub(res, mul(2, inv3));
    return res;
}

int f2(int x, int y)
{
    int res = mul(inv4, mul(y + 1, mul(x, x + 4)));
    if (x % 2 == 1)
    {
        res = add(res, mul(inv4, y + 1));
        if (y % 2 == 0)
            if (x % 4 == 1)
                res = sub(res, inv2);
            else
                res = add(res, inv2);
    }
    return res;
}

int f(int x, int y)
{
    if (x < y)
        return f(y, x);
    --x; --y;
    int res = 0;
    if (y < x / 2)
    {
        res = add(res, f2(x, y));
        x = y * 2;
        res = sub(res, f2(x, y));
    }
    res = add(res, add(f3(x, y), add(f4(x), f4(y))));
    return res;
}

int solve()
{
    int x, y, n, m; scanf("%d%d%d%d", &x, &y, &n, &m);
    --x; --y;
    int res = sub(add(f(n, m), f(x, y)), add(f(x, m), f(n, y)));
    if (x == 2 && y == 2)
        res = add(res, 2);
    return res;
}

int main()
{
    int t; scanf("%d", &t);
    for (int i = 1; i <= t; ++i)
        printf("%d\n", solve());
}

#include <cstdio>
const int MOD = 1000000007;
const int inv2 = 500000004;
const int inv3 = 333333336;
const int inv4 = 250000002;
const int inv6 = 166666668;
const int inv72 = 13888889;
const int magic3[3] = {0, -32, -16};
const int magic6[6] = {-16, 36, -32, 20, 0, 4};

int _add(int x) { return x < MOD ? x : x - MOD; }
int add(int x, int y) { return _add(x + y); }
int _sub(int x) { return x < 0 ? x + MOD : x; }
int sub(int x, int y) { return _sub(x - y); }
int mul(int x, int y) { return 1LL * x * y % MOD; }

int f4(int x)
{
    int res = mul(x + 6, mul(x, x));
    if (x % 2 == 0)
        res = add(res, MOD + magic3[x / 2 % 3]);
    else
        res = add(res, add(mul(9, x), MOD + magic6[(x - 1) / 2 % 6]));
    res = mul(inv72, res);
    return res;
}

int f3(int x, int y)
{
    int res = mul(inv6, mul(add(x, y) + 4, mul(x + 1, y + 1)));
    if (x % 3 + y % 3 < 2)
        res = sub(res, mul(inv3, 2));
    return res;
}

int f2(int x, int y)
{
    int res = mul(inv4, mul(y + 1, mul(x, x + 4)));
    if (x % 2 == 1)
    {
        res = add(res, mul(inv4, y + 1));
        if (y % 2 == 0)
            if (x % 4 == 1)
                res = sub(res, inv2);
            else
                res = add(res, inv2);
    }
    return res;
}

int f(int x, int y)
{
    if (x < y)
        return f(y, x);
    int res = 0;
    if (y < x / 2)
    {
        res = add(res, f2(x, y));
        x = y * 2;
        res = sub(res, f2(x, y));
    }
    res = add(res, add(f3(x, y), add(f4(x), f4(y))));
    return res;
}

int solve()
{
    int x, y, n, m; scanf("%d%d%d%d", &x, &y, &n, &m);
    --x; --y; --n; --m;
    --x; --y;
    int res = sub(add(f(n, m), f(x, y)), add(f(x, m), f(n, y)));
    if (x == 1 && y == 1)
        res = add(res, 2);
    return res;
}

int main()
{
    int t; scanf("%d", &t);
    for (int i = 1; i <= t; ++i)
        printf("%d\n", solve());
}

#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long LL;const int Mod = 1000000007;const int Inv2 = (Mod + 1) / 2,Inv8 = (Mod + 1) / 8,Inv24 = (Mod + 1) / 24;int g[6][6];
inline int f1(int x) {int ret = 0;if (x < 3) ret = 0;else if (x & 1) ret = ((3ll * x * x % Mod * x + 2ll * x * x - 3ll * x - 18) % Mod + Mod) * Inv8 % Mod;
	else ret = ((3ll * x * x % Mod * x + 2ll * x * x - 4ll * x - 16) % Mod + Mod) * Inv8 % Mod;return ret;}
inline int fk(int x, int y) {int z = x + y, ret = 0;int w = z / 3;if (z % 3 == 1) ++w, ret = ((3ll * w * w % Mod * w - 3ll * w * w + 2ll * w) % Mod + Mod) * Inv2 % Mod;
	if (z % 3 == 0) ret = ((3ll * w * w % Mod * w + 3ll * w * w + 2ll * w) % Mod + Mod) * Inv2 % Mod;
	if (z % 3 == 2) ret = ((3ll * w * w % Mod * w + 9ll * w % Mod * w + 10ll * w + 4) % Mod + Mod) * Inv2 % Mod;return ret;}
int f2(int x, int y) {if (x > y) std::swap(x, y);if (x < 3) return 0;if (y <= 5) return g[x][y];
	int ret = (f1(x / 2) + f1(y / 2)) % Mod;ret = (ret - f2(x / 2, y / 2) + Mod) % Mod;ret = (ret + fk(x, y)) % Mod;
	ret = (ret - fk(y / 2, y) + Mod) % Mod;ret = (ret - fk(x, x / 2) + Mod) % Mod;ret = (ret + fk(y / 2, x / 2)) % Mod;return ret;}
inline int f3(int y) {int d = 0;if (~y & 1) ++y, d = 1;int ret = ((2ll * y * y % Mod * y - 9ll * y % Mod * y - 26ll * y + 105) % Mod + Mod) * Inv24 % Mod;
	if (d) {int q = (LL)((y - 2) / 4) * ((y + 1) / 2) % Mod;q = (q + (LL)((y - 4) / 4) * (y / 2)) % Mod;ret = (ret - q + Mod) % Mod;}return ret;}
inline int f4(int x, int y) {int ret = f3(y);int z = y - (x - 2) * 2;int q = f3(z);int d = 0;if (~z & 1) ++z, d = 1;
	int q2 = (LL)(z / 2 - 1) * (z / 2 - 2) % Mod;if (d) q2 = (q2 - (z - 5) / 2 + Mod) % Mod;q = (q + (LL)q2 * (x - 2)) % Mod;ret = (ret - q + Mod) % Mod;return ret;}
inline int f(int x, int y) {if (x > y) std::swap(x, y);if (x < 3) return 0;if (x * 2 <= y) return ((LL)f1(x) + f4(x, y) + f3(x)) % Mod;else return ((LL)f2(x, y) + f3(y) + f3(x)) % Mod;}
int main() {g[3][3] = 4;g[3][4] = 7;g[3][5] = 9;g[4][4] = 12;g[4][5] = 17;g[5][5] = 26;int Tests;scanf("%d", &Tests);
	while (Tests--) {int X, Y, N, M;scanf("%d%d%d%d", &X, &Y, &N, &M);int Ans = f(N, M);Ans = (Ans - f(X - 1, M) + Mod) % Mod;
		Ans = (Ans - f(N, Y - 1) + Mod) % Mod;Ans = (Ans + f(X - 1, Y - 1)) % Mod;printf("%d\n", Ans);}return 0;}

#include <cstdio>
#include <algorithm>

typedef long long LL;
const int Mod = 1000000007;
const int Inv2 = (Mod + 1) / 2;
const int Inv8 = (Mod + 1) / 8;
const int Inv24 = (Mod + 1) / 24;

int g[6][6];
inline int f1(int x) {
	int ret = 0;
	if (x < 3) ret = 0;
	else if (x & 1) ret = ((3ll * x * x % Mod * x + 2ll * x * x - 3ll * x - 18) % Mod + Mod) * Inv8 % Mod;
	else ret = ((3ll * x * x % Mod * x + 2ll * x * x - 4ll * x - 16) % Mod + Mod) * Inv8 % Mod;
//	printf("f1(%d) = %d\n", x, ret);
	return ret;
}
inline int fk(int x, int y) {
	int z = x + y, ret = 0;
	int w = z / 3;
	if (z % 3 == 1) ++w, ret = ((3ll * w * w % Mod * w - 3ll * w * w + 2ll * w) % Mod + Mod) * Inv2 % Mod;
	if (z % 3 == 0) ret = ((3ll * w * w % Mod * w + 3ll * w * w + 2ll * w) % Mod + Mod) * Inv2 % Mod;
	if (z % 3 == 2) ret = ((3ll * w * w % Mod * w + 9ll * w % Mod * w + 10ll * w + 4) % Mod + Mod) * Inv2 % Mod;
//	printf("fk(%d, %d) = %d\n", x, y, ret);
	return ret;
}
int f2(int x, int y) {
	if (x > y) std::swap(x, y);
	if (x < 3) return 0;
	if (y <= 5) return g[x][y];
	int ret = (f1(x / 2) + f1(y / 2)) % Mod;
	ret = (ret - f2(x / 2, y / 2) + Mod) % Mod;
	ret = (ret + fk(x, y)) % Mod;
	ret = (ret - fk(y / 2, y) + Mod) % Mod;
	ret = (ret - fk(x, x / 2) + Mod) % Mod;
	ret = (ret + fk(y / 2, x / 2)) % Mod;
//	printf("f2(%d, %d) = %d\n", x, y, ret);
	return ret;
}
inline int f3(int y) {
	int d = 0;
	if (~y & 1) ++y, d = 1;
	int ret = ((2ll * y * y % Mod * y - 9ll * y % Mod * y - 26ll * y + 105) % Mod + Mod) * Inv24 % Mod;
	if (d) {
		int q = (LL)((y - 2) / 4) * ((y + 1) / 2) % Mod;
		q = (q + (LL)((y - 4) / 4) * (y / 2)) % Mod;
		ret = (ret - q + Mod) % Mod;
	}
//	printf("f3(%d) = %d\n", y - d, ret);
	return ret;
}
inline int f4(int x, int y) {
	int ret = f3(y);
	int z = y - (x - 2) * 2;
	int q = f3(z);
	int d = 0;
	if (~z & 1) ++z, d = 1;
	int q2 = (LL)(z / 2 - 1) * (z / 2 - 2) % Mod;
	if (d) q2 = (q2 - (z - 5) / 2 + Mod) % Mod;
	q = (q + (LL)q2 * (x - 2)) % Mod;
	ret = (ret - q + Mod) % Mod;
//	printf("f4(%d, %d) = %d\n", x, y, ret);
	return ret;
}
inline int f(int x, int y) {
	if (x > y) std::swap(x, y);
	if (x < 3) return 0;
	if (x * 2 <= y) return ((LL)f1(x) + f4(x, y) + f3(x)) % Mod;
	else return ((LL)f2(x, y) + f3(y) + f3(x)) % Mod;
}

int main() {
	g[3][3] = 4;
	g[3][4] = 7;
	g[3][5] = 9;
	g[4][4] = 12;
	g[4][5] = 17;
	g[5][5] = 26;
//	for (int i = 3; i <= 20; ++i, puts(""))
//		for (int j = 3; j <= 20; ++j)
//			printf("%d, ", f(i, j));
	int Tests;
	scanf("%d", &Tests);
	while (Tests--) {
		int X, Y, N, M;
		scanf("%d%d%d%d", &X, &Y, &N, &M);
		int Ans = f(N, M);
		Ans = (Ans - f(X - 1, M) + Mod) % Mod;
		Ans = (Ans - f(N, Y - 1) + Mod) % Mod;
		Ans = (Ans + f(X - 1, Y - 1)) % Mod;
		printf("%d\n", Ans);
	}
	return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long LL;
const int Mod = 1000000007;
const int Inv2 = (Mod + 1) / 2;
const int Inv8 = (Mod + 1) / 8;
const int Inv24 = (Mod + 1) / 24;

int g[6][6];
inline int f1(int x) {
	int ret = 0;
	if (x < 3) ret = 0;
	else if (x & 1) ret = ((3ll * x * x % Mod * x + 2ll * x * x - 3ll * x - 18) % Mod + Mod) * Inv8 % Mod;
	else ret = ((3ll * x * x % Mod * x + 2ll * x * x - 4ll * x - 16) % Mod + Mod) * Inv8 % Mod;
	return ret;
}
inline int fk(int x, int y) {
	int z = x + y, ret = 0;
	int w = z / 3;
	if (z % 3 == 1) ++w, ret = ((3ll * w * w % Mod * w - 3ll * w * w + 2ll * w) % Mod + Mod) * Inv2 % Mod;
	if (z % 3 == 0) ret = ((3ll * w * w % Mod * w + 3ll * w * w + 2ll * w) % Mod + Mod) * Inv2 % Mod;
	if (z % 3 == 2) ret = ((3ll * w * w % Mod * w + 9ll * w % Mod * w + 10ll * w + 4) % Mod + Mod) * Inv2 % Mod;
	return ret;
}
int f2(int x, int y) {
	if (x > y) std::swap(x, y);
	if (x < 3) return 0;
	if (y <= 5) return g[x][y];
	int ret = (f1(x / 2) + f1(y / 2)) % Mod;
	ret = (ret - f2(x / 2, y / 2) + Mod) % Mod;
	ret = (ret + fk(x, y)) % Mod;
	ret = (ret - fk(y / 2, y) + Mod) % Mod;
	ret = (ret - fk(x, x / 2) + Mod) % Mod;
	ret = (ret + fk(y / 2, x / 2)) % Mod;
	return ret;
}
inline int f3(int y) {
	int d = 0;
	if (~y & 1) ++y, d = 1;
	int ret = ((2ll * y * y % Mod * y - 9ll * y % Mod * y - 26ll * y + 105) % Mod + Mod) * Inv24 % Mod;
	if (d) {
		int q = (LL)((y - 2) / 4) * ((y + 1) / 2) % Mod;
		q = (q + (LL)((y - 4) / 4) * (y / 2)) % Mod;
		ret = (ret - q + Mod) % Mod;
	}
	return ret;
}
inline int f4(int x, int y) {
	int ret = f3(y);
	int z = y - (x - 2) * 2;
	int q = f3(z);
	int d = 0;
	if (~z & 1) ++z, d = 1;
	int q2 = (LL)(z / 2 - 1) * (z / 2 - 2) % Mod;
	if (d) q2 = (q2 - (z - 5) / 2 + Mod) % Mod;
	q = (q + (LL)q2 * (x - 2)) % Mod;
	ret = (ret - q + Mod) % Mod;
	return ret;
}
inline int f(int x, int y) {
	if (x > y) std::swap(x, y);
	if (x < 3) return 0;
	if (x * 2 <= y) return ((LL)f1(x) + f4(x, y) + f3(x)) % Mod;
	else return ((LL)f2(x, y) + f3(y) + f3(x)) % Mod;
}

int main() {
	g[3][3] = 4;
	g[3][4] = 7;
	g[3][5] = 9;
	g[4][4] = 12;
	g[4][5] = 17;
	g[5][5] = 26;
	int Tests;
	scanf("%d", &Tests);
	while (Tests--) {
		int X, Y, N, M;
		scanf("%d%d%d%d", &X, &Y, &N, &M);
		int Ans = f(N, M);
		Ans = (Ans - f(X - 1, M) + Mod) % Mod;
		Ans = (Ans - f(N, Y - 1) + Mod) % Mod;
		Ans = (Ans + f(X - 1, Y - 1)) % Mod;
		printf("%d\n", Ans);
	}
	return 0;
}

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <list>
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

const int MOD = 1000000007;
void inc(int& a, int b) { if ((a += b) >= MOD) a -= MOD; }
void dec(int& a, int b) { inc(a, MOD - b); }

int qx, qy, xdim, ydim;
int inv[6 + 1];

int calcformula(int x, int y) {
	int ret = max(max((x + 1) / 2, (y + 1) / 2), (x + y + 2) / 3);
	if (ret % 2 != (x + y) % 2) ++ret;
	return ret;
}

int calc(int x, int y) {
	if (x == 1 && y == 0 || x == 0 && y == 1) return 3;
	if (x == 1 && y == 1) return xdim > 3 || ydim > 3 ? 4 : 0;
	if (x == 2 && y == 2) return 4;
	if (x == 3 && y == 0 && xdim == 4 || x == 0 && y == 3 && ydim == 4) return 5;
	return calcformula(x, y);
}

int divup(int num, int den) { if (den < 0) num = -num, den = -den; return num >= 0 ? (num + den - 1) / den : num / den; }
int divdn(int num, int den) { if (den < 0) num = -num, den = -den; return num >= 0 ? num / den : (num - den + 1) / den; }
int makesamepar(int a, int b) { if ((a & 1) != (b & 1)) ++a; return a; }
int cnt(int lo, int hi) { return hi - lo + 1; }
int sum(int lo, int hi) { return (ll)(lo + hi) * (hi - lo + 1) / 2 % MOD; }
int sumsq(int n) { return (ll)n * (n + 1) % MOD * (2 * n + 1) % MOD * inv[6] % MOD; }
int sumsq(int lo, int hi) { int ret = 0; inc(ret, sumsq(hi)); if (lo != 0) dec(ret, sumsq(lo - 1)); return ret; }

int calcsumstupid(int xlim, int ylim) {
	int ret = 0; REPE(x, xlim) REPE(y, ylim) inc(ret, calc(x, y)); return ret;
}

int calcsum(int xlim, int ylim) {
	// sum(x=0..xlim,y=0..ylim,makesamepar(max(ceil(x/2),ceil(y/2),ceil((x+y)/3)),x+y))
	// sum(dx=0..kx-1,dy=0..ky-1,x=0..(xlim-dx)/kx,y=0..(ylim-dy)/kx,makesamepar(max(ceil((x*kx+dx)/2),ceil((y*ky+dy)/2),ceil((x*kx+dx+y*ky+dy)/3)),x*kx+dx+y*ky+dy))
	// sum(dx=0..6kx-1,dy=0..6ky-1,x=0..(xlim-dx)/(6kx),y=0..(ylim-dy)/(6ky),makesamepar(max(3kx*x+ceil(dx/2),3ky*y+ceil(dy/2),2kx*x+2ky*y+ceil((dx+dy)/3)),dx+dy))

	// sum(dx=0..12kx-1,dy=0..6ky-1,x=0..(xlim-dx)/(12kx),y=0..(ylim-dy)/(6ky),makesamepar(max(6kx*x+ceil(dx/2),3ky*y+ceil(dy/2),4kx*x+2ky*y+ceil((dx+dy)/3)),dx+dy))
	// y >= (2kx*x+ceil(dx/2)-ceil((dx+dy)/3))/(2ky)
	// y <= (4kx*x+ceil((dx+dy)/3)-ceil(dy/2))/(ky)

	// sum(dx=0..11,dy=0..5,x=0..(xlim-dx)/12,y=0..(ylim-dy)/6,makesamepar(max(6*x+ceil(dx/2),3*y+ceil(dy/2),4*x+2*y+ceil((dx+dy)/3)),dx+dy))
	// y >= x+ceil((ceil(dx/2)-ceil((dx+dy)/3))/2)
	// y <= 4*x+ceil((dx+dy)/3)-ceil(dy/2)

	// part1=sum(dx=0..11,dy=0..5,x=0..(xlim-dx)/12,y=0..(ylim-dy)/6,y<x+ceil((ceil(dx/2)-ceil((dx+dy)/3))/2),6*x+makesamepar(ceil(dx/2),dx+dy))
	// part2=sum(dx=0..11,dy=0..5,x=0..(xlim-dx)/12,y=0..(ylim-dy)/6,x+ceil((ceil(dx/2)-ceil((dx+dy)/3))/2)<=y<=4*x+ceil((dx+dy)/3)-ceil(dy/2),4*x+2*y+makesamepar(ceil((dx+dy)/3),dx+dy))
	// part3=sum(dx=0..5,dy=0..11,x=0..(xlim-dx)/6,y=0..(ylim-dy)/12,y>x+floor((ceil((dx+dy)/3)-ceil(dy/2))/2),6*y+makesamepar(ceil(dy/2),dx+dy))

	int ret = 0;
	//vector<vector<int>> cnt(xlim + 1, vector<int>(ylim + 1, 0));
	// part1
	REP(dx, 12) if (dx <= xlim) REP(dy, 6) if (dy <= ylim) {
		// sum(x=0..(xlim-dx)/12,y=0..(ylim-dy)/6,y<x+ceil((ceil(dx/2)-ceil((dx+dy)/3))/2),6*x+makesamepar(ceil(dx/2),dx+dy)) = sum(x=0..A,y=0..min(B,x+D),6*x+E)
		int A = (xlim - dx) / 12, B = (ylim - dy) / 6, D = divup(divup(dx, 2) - divup(dx + dy, 3), 2) - 1, E = makesamepar(divup(dx, 2), dx + dy);
		//REPE(x, A) FORE(y, 0, min(B, x + D)) { int xx = 12 * x + dx, yy = 6 * y + dy; assert(xx >= 0 && xx <= xlim); assert(yy >= 0 && yy <= ylim); ++cnt[xx][yy]; }
		int cur = 0;
		{ // sum(x=max(0,B-D)..A,y=0..B,6*x+E)
			int xlo = max(0, B - D), xhi = A, ylo = 0, yhi = B;
			if (xlo <= xhi && ylo <= yhi) {
				cur = (cur + (ll)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E) % MOD;
				cur = (cur + (ll)cnt(ylo, yhi) * sum(xlo, xhi) % MOD * 6) % MOD;
			}
		}
		{ // sum(x=0..min(A,B-D-1),y=0..x+D,6*x+E)
			int xlo = max(0, -D), xhi = min(A, B - D - 1);
			if (xlo <= xhi) {
				// E*sum(x=xlo..xhi,x+D+1) -> E*(D+1)*sum(x=xlo..xhi,1) + E*sum(x=xlo..xhi,x)
				// 6*sum(x=xlo..xhi,y=0..x+D,x) -> 6*(D+1)*sum(x=xlo..xhi,x) + 6*sum(x=xlo..xhi,x*x)
				cur = (cur + (ll)cnt(xlo, xhi) * E % MOD * (D + 1)) % MOD;
				cur = (cur + (ll)sum(xlo, xhi) * E) % MOD;
				cur = (cur + (ll)sum(xlo, xhi) * 6 % MOD * (D + 1)) % MOD;
				cur = (cur + (ll)sumsq(xlo, xhi) * 6) % MOD;
			}
		}
		//int chk = 0; REPE(x, A) FORE(y, 0, min(B, x + D)) { int xx = 12 * x + dx, yy = 6 * y + dy; inc(chk, calcformula(xx, yy)); } assert(cur == chk);
		inc(ret, cur);
	}

	// part2
	REP(dx, 12) if (dx <= xlim) REP(dy, 6) if (dy <= ylim) {
		// sum(x=0..(xlim-dx)/12,y=0..(ylim-dy)/6,x+ceil((ceil(dx/2)-ceil((dx+dy)/3))/2)<=y<=4*x+ceil((dx+dy)/3)-ceil(dy/2),4*x+2*y+makesamepar(ceil((dx+dy)/3),dx+dy)) = sum(x=0..A,y=max(0,x+C)..min(B,4x+D),4*x+2*y+E)
		int A = (xlim - dx) / 12, B = (ylim - dy) / 6, C = divup(divup(dx, 2) - divup(dx + dy, 3), 2), D = divup(dx + dy, 3) - divup(dy, 2), E = makesamepar(divup(dx + dy, 3), dx + dy);
		//REPE(x, A) FORE(y, max(0, x + C), min(B, 4 * x + D)) { int xx = 12 * x + dx, yy = 6 * y + dy; assert(xx >= 0 && xx <= xlim); assert(yy >= 0 && yy <= ylim); ++cnt[xx][yy]; }
		int cur = 0;
		{ // +sum(x=max(0,ceil((B-D)/4))..A,y=0..B,4*x+2*y+E)
			int xlo = max(0, divup(B - D, 4)), xhi = A, ylo = 0, yhi = B;
			if (xlo <= xhi && ylo <= yhi) {
				cur = (cur + (ll)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E) % MOD;
				cur = (cur + (ll)cnt(ylo, yhi) * sum(xlo, xhi) % MOD * 4) % MOD;
				cur = (cur + (ll)cnt(xlo, xhi) * sum(ylo, yhi) % MOD * 2) % MOD;
			}
		}
		{ // +sum(x=0..min(A,ceil((B-D)/4)-1),y=0..4x+D,4*x+2*y+E)
			int xlo = max(0, divup(-D, 4)), xhi = min(A, divup(B - D, 4) - 1);
			if (xlo <= xhi) {
				// sum(x=xlo..xhi,y=0..4x+D,4x+2y+E) -> E*sum(x=xlo..xhi,4x+D+1) + 4*sum(x=xlo..xhi,4xx+x*(D+1)) + sum(x=xlo..xhi,16xx+4x*(2D+1)+D*(D+1))
				cur = (cur + (ll)cnt(xlo, xhi) * E % MOD * (D + 1)) % MOD;
				cur = (cur + (ll)sum(xlo, xhi) * E % MOD * 4) % MOD;
				cur = (cur + (ll)sumsq(xlo, xhi) * 16) % MOD;
				cur = (cur + (ll)sum(xlo, xhi) * (D + 1) % MOD * 4) % MOD;
				cur = (cur + (ll)sumsq(xlo, xhi) * 16) % MOD;
				cur = (cur + (ll)sum(xlo, xhi) * (2 * D + 1) % MOD * 4) % MOD;
				cur = (cur + (ll)cnt(xlo, xhi) * D % MOD * (D + 1)) % MOD;
			}
		}
		{ // -sum(x=max(0,B-C+1,ceil((B-D)/4))..A,y=0..B,4*x+2*y+E)
			int xlo = max(0, max(B - C + 1, divup(B - D, 4))), xhi = A, ylo = 0, yhi = B;
			if (xlo <= xhi && ylo <= yhi) {
				// -sum(x=xlo..xhi,4*x+2*y+E)
				cur = (cur - (ll)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E % MOD + MOD) % MOD;
				cur = (cur - (ll)cnt(ylo, yhi) * sum(xlo, xhi) % MOD * 4 % MOD + MOD) % MOD;
				cur = (cur - (ll)cnt(xlo, xhi) * sum(ylo, yhi) % MOD * 2 % MOD + MOD) % MOD;
			}
		}
		{ // -sum(x=max(0,ceil((C-D-1)/3)..min(A,B-C),y=0..x+C-1,4*x+2*y+E)
			int xlo = max(0, max(1 - C, divup(C - D - 1, 3))), xhi = min(A, B - C);
			if (xlo <= xhi) {
				// -sum(x=xlo..xhi,y=0..x+C-1,4*x+2*y+E) -> -E*sum(x=xlo..xhi,x+C) -sum(x=xlo..xhi,4xx+4C*x) -sum(x=xlo..xhi,xx+x*(2C-1)+(C-1)*C)
				cur = (cur - (ll)cnt(xlo, xhi) * E % MOD * C % MOD + MOD) % MOD;
				cur = (cur - (ll)sum(xlo, xhi) * E % MOD + MOD) % MOD;
				cur = (cur - (ll)sumsq(xlo, xhi) * 4 % MOD + MOD) % MOD;
				cur = (cur - (ll)sum(xlo, xhi) * C % MOD * 4 % MOD + MOD) % MOD;
				cur = (cur - (ll)sumsq(xlo, xhi) % MOD + MOD) % MOD;
				cur = (cur - (ll)sum(xlo, xhi) * (2 * C - 1) % MOD + MOD) % MOD;
				cur = (cur - (ll)cnt(xlo, xhi) * (C - 1) % MOD * C % MOD + MOD) % MOD;
			}
		}
		{ // -sum(x=0..min(A,ceil((B-D)/4)-1,ceil((C-D-1)/3)-1),y=0..4x+D,4*x+2*y+E)
			int xlo = max(0, divup(-D, 4)), xhi = min(A, min(divup(B - D, 4) - 1, divup(C - D - 1, 3) - 1));
			if (xlo <= xhi) {
				// -sum(x=xlo..xhi,y=0..4x+D,4*x+2*y+E)
				cur = (cur - (ll)cnt(xlo, xhi) * E % MOD * (D + 1) % MOD + MOD) % MOD;
				cur = (cur - (ll)sum(xlo, xhi) * E % MOD * 4 % MOD + MOD) % MOD;
				cur = (cur - (ll)sumsq(xlo, xhi) * 16 % MOD + MOD) % MOD;
				cur = (cur - (ll)sum(xlo, xhi) * (D + 1) % MOD * 4 % MOD + MOD) % MOD;
				cur = (cur - (ll)sumsq(xlo, xhi) * 16 % MOD + MOD) % MOD;
				cur = (cur - (ll)sum(xlo, xhi) * (2 * D + 1) % MOD * 4 % MOD + MOD) % MOD;
				cur = (cur - (ll)cnt(xlo, xhi) * D % MOD * (D + 1) % MOD + MOD) % MOD;
			}
		}
		//int chk = 0; REPE(x, A) FORE(y, max(0, x + C), min(B, 4 * x + D)) { int xx = 12 * x + dx, yy = 6 * y + dy; inc(chk, calcformula(xx, yy)); } assert(cur == chk);
		inc(ret, cur);
	}

	// part3
	REP(dx, 6) if (dx <= xlim) REP(dy, 12) if (dy <= ylim) {
		// sum(x=0..(xlim-dx)/3,y=0..(ylim-dy)/12,y>x+ceil((dx+dy)/3)-ceil(dy/2),6*y+makesamepar(ceil(dy/2),dx+dy)) = sum(x=0..A,y=max(0,x+C)..B,6*y+E)
		int A = (xlim - dx) / 6, B = (ylim - dy) / 12, C = divdn(divup(dx + dy, 3) - divup(dy, 2),2) + 1, E = makesamepar(divup(dy, 2), dx + dy);
		//REPE(x, A) FORE(y, max(0, x + C), B) { int xx = 6 * x + dx, yy = 12 * y + dy; assert(xx >= 0 && xx <= xlim); assert(yy >= 0 && yy <= ylim); ++cnt[xx][yy]; }
		int cur = 0;
		{ // sum(x=0..min(A,-C),y=0..B,6*y+E)
			int xlo = 0, xhi = min(A, -C), ylo = 0, yhi = B;
			if (xlo <= xhi && ylo <= yhi) {
				cur = (cur + (ll)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E) % MOD;
				cur = (cur + (ll)cnt(xlo, xhi) * sum(ylo, yhi) % MOD * 6) % MOD;
			}
		}
		{ // sum(x=max(0,-C+1)..A,y=x+C..B,6*y+E)
			int xlo = max(0, -C + 1), xhi = min(A, B - C);
			if (xlo <= xhi) {
				// E*sum(x=xlo..xhi,B-C+1-x) -> E*sum(x=xlo..xhi,B-C+1) - E*sum(x=xlo..xhi,x)
				// sum(x=xlo..xhi,y=x+C..B,6*y) -> 3*sum(x=xlo..xhi,(C+B)*(B-C+1)-x*(2C-1)-x*x)
				cur = (cur + (ll)cnt(xlo, xhi) * E % MOD * (B - C + 1)) % MOD;
				cur = (cur - (ll)sum(xlo, xhi) * E % MOD + MOD) % MOD;
				cur = (cur + (ll)cnt(xlo, xhi) * (C + B) % MOD * (B - C + 1) % MOD * 3) % MOD;
				cur = (cur - (ll)sum(xlo, xhi) * (2 * C - 1) % MOD * 3 % MOD + MOD) % MOD;
				cur = (cur - (ll)sumsq(xlo, xhi) * 3 % MOD + MOD) % MOD;
			}
		}
		//int chk = 0; REPE(x, A) FORE(y, max(0, x + C), B) { int xx = 6 * x + dx, yy = 12 * y + dy; inc(chk, calcformula(xx, yy)); } assert(cur == chk);
		inc(ret, cur);
	}
	//REPE(x, xlim) { printf("%2d: ", x); REPE(y, ylim) printf("%d", cnt[x][y]); puts(""); }
	//REPE(x, xlim) REPE(y, ylim) if (cnt[x][y] != 1) { printf("(%d,%d)\n", x, y); exit(0); }
	vector<pair<int, int>> special; special.PB(MP(1, 0)); special.PB(MP(0, 1)); special.PB(MP(1, 1)); special.PB(MP(3, 0)); special.PB(MP(0, 3)); special.PB(MP(2, 2));
	REPSZ(i, special) {
		int x, y; tie(x, y) = special[i];
		if (x <= xlim && y <= ylim) {
			dec(ret, calcformula(x, y));
			inc(ret, calc(x, y));
		}
	}
	return ret;
}

void precalc() {
	inv[1] = 1; FORE(i, 2, 6) inv[i] = (ll)(MOD - MOD / i) * inv[MOD % i] % MOD;
}

int solve() {
	int ret = 0;
	inc(ret, calcsum(xdim - 1, ydim - 1));
	dec(ret, calcsum(xdim - 1, qy - 1));
	dec(ret, calcsum(qx - 1, ydim - 1));
	inc(ret, calcsum(qx - 1, qy - 1));
	return ret;
}

void run() {
	scanf("%d%d%d%d", &qx, &qy, &xdim, &ydim); --qx, --qy;
	printf("%d\n", solve());
}

void verifycalc() {
	for (xdim = 3; xdim <= 20; ++xdim) for (ydim = 3; ydim <= 20; ++ydim) {
		vector<vector<int>> d(xdim, vector<int>(ydim, INT_MAX));
		queue<pair<int, int>> q;
		d[0][0] = 0, q.push(MP(0, 0));
		while (!q.empty()) {
			int x, y; tie(x, y) = q.front(); q.pop();
			FORE(dx, -2, +2) FORE(dy, -2, +2) if (dx * dx + dy * dy == 5) {
				int nx = x + dx, ny = y + dy;
				if (nx < 0 || nx >= xdim || ny < 0 || ny >= ydim) continue;
				if (d[nx][ny] == INT_MAX) d[nx][ny] = d[x][y] + 1, q.push(MP(nx, ny));
			}
		}
		//REP(x, xdim) REP(y, ydim) printf("(%d,%d) -> %d vs %d\n", x, y, d[x][y], calc(x, y));
		REP(x, xdim) REP(y, ydim) if (d[x][y] == INT_MAX) { assert(xdim == 3 && ydim == 3 && x == 1 && y == 1); d[x][y] = 0; }
		REP(x, xdim) REP(y, ydim) assert(d[x][y] == calc(x, y));
		printf("done (%d,%d)\n", xdim, ydim);
	}
}

void verifysum() {
	for (xdim = 3; xdim <= 100; ++xdim) {
		for (ydim = 3; ydim <= 100; ++ydim) FORE(dx,1,min(xdim,3)) FORE(dy,1,min(ydim,3)) {
			int have = calcsum(xdim - dx, ydim - dy);
			int want = calcsumstupid(xdim - dx, ydim - dy);
			assert(have == want);
		}
		printf("done xdim=%d\n", xdim);
	}
}

int main() {
	precalc();
	//verifycalc();
	//verifysum();
	int ncase; scanf("%d", &ncase); FORE(i, 1, ncase) run();
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int> > typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

li kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

li zbirost(li x, li y)
{
    x++; y++;
    if (x%3==0 || y%3==0) return x*y/3*3;
    if (x%3==1 && y%3==1) return x*y/3*3 + (x+y-2)%3;
    if (x%3==2 && y%3==2) return x*y/3*3 - 3 + (x+y-2)%3 + (x+y-3)%3 + (x+y-3)%3 + (x+y-4)%3;
    else return x*y/3*3 + (x+y-2)%3 + (x+y-3)%3;
}

li summ(li x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

li presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

li presumsum(li x)
{
    return x*(x+1)%mod*(x+2)%mod*inv(6)%mod;
}

li oduzm_red(li p, li k)
{
    //(sum(p) + sum(p+1) + sum(p+2) + sum(p+3)) + (sum(p+2)+sum(p+3)+sum(p+4)+sum(p+5)) + ...
    //suma prvih k+1 elem.  blokovi su mod 4

    li kk=(k/4*4+3)/2+2;
    li res=presumsum(p+kk)+presumsum(p+kk-2)-presumsum(p+1)-presumsum(p-1);
    if (k%4<=2) (res-=sum(p+kk))%=mod;
    if (k%4<=1) (res-=sum(p+kk-1))%=mod;
    if (k%4<=0) (res-=sum(p+kk-2))%=mod;
    if (res<0) res+=mod;

    //cout<<p<<" "<<k<<" "<<kk<<": "<<res<<endl;
    return res;
}

li dunkcija(li x, li y)
{
    if (2*x>y) return 0;

    li res=0;
    if (y%2==0)
    {
        li fakex=y/2; //cout<<fakex<<" "<<x<<": ";
        res+=(fakex-x+1)*(sum(fakex)%mod)+(fakex-x)*(sum(fakex+1)%mod);
        res-=oduzm_red(x-1,y-2*x); if (res<0) res+=mod;

        return res;
    }
    else
    {
        res=dunkcija(x,y-1);
        li fakex=y/2+1;

        res+=(fakex-x)*fakex+fakex/2;
        if (y%4==1) res-=x/2;
        else res-=(x+1)/2;
        return res%mod;
    }
}

li predukcija(li x)
{
    //racuna prefiksnu sumu za prvih x+1 elemenata eledeceg niza: 0,1,2,1,2,3,2,3,4,3,4,5,4,5,6,5,6,7,...

    li res = sum(x);
    res-=6*sum(x/3);

    //cout<<sum(x)<<"-"<<6*sum(x/3)<<" = ";

    if (x%3<=1) res+=2*(x/3);
    if (x%3<=0) res+=2*(x/3);

    res%=mod; if (res<0) res+=mod;

    //cout<<x<<": "<<res<<endl;

    return res;
}

li redunkcija(li k)
{
    k--;
    return (sum(k+1)%mod*9%mod+(li)presumsum(k)*12)%mod;
}

li true_val(li x)
{
    li res=0;
    for (li i=1;i<=x;i+=2)
    {
        (res+=predukcija(i))%=mod;
    }

    return res;
}
li paradunkcija(li x)
{
    //neka je p predukcija skraceno
    //racuna p(1)+p(3)+p(5)+...+p(x), x je garantovano neparno

    //suma po modovima hahahahhaha
    //tacnije, p(1) + p(7) + p(13) + ... itd za ostale kurceve

    if (x==0) return 0;
    if (x==1) return 1;
    if (x==3) return 5;
    if (x==5) return 14;

    li mod5 = redunkcija((x+1)/6);
    li mod1 = redunkcija((x-1)/6)+4ll*sum((x-1)/6);
    li mod3 = redunkcija((x-3)/6)+8ll*sum((x-3)/6);

    mod1+=((x-1)/6+1);
    mod3+=4ll*((x-3)/6+1);

    /*cout<<"baza: "<<redunkcija((x-1)/6)<<endl;
    cout<<"dodatak na bazu: 2 puta " << 2ll*sum((x-1)/6)<<endl;
    cout<<"dodatni kurac: "<<((x-1)/6+1)<<endl;
    cout<<"ukupno: "<<mod1<<endl<<endl;*/
    //cout<<"k je jednako = "<<(x+1)/6<<endl;

    return ((mod1%mod + mod5%mod)%mod + mod3%mod)%mod;

    return 0;

    /*int res=0;
    for (int i=1;i<=x;i+=2) (res+=predukcija(i))%=mod;

    return res;*/
}

li test_abdukcija(li x, li y)
{
    li fres=0;
    fff(i,x,y/2) fff(j,2*i,y)
    {
        (fres+=(i+j)/3+(i+j)%3)%=mod;
    }
    return fres;
}
li anti_dunkcija(li x, li y)
{
    if (2*x>y) return 0;

    li fx=y/2,res=-69420;
    if (y%2==1)
    {
        x--;
        res=(fx-x)*(fx-x+1)%mod*(fx+1)%mod - 2*kvsum(fx-x);
        if (res<0) res+=mod; if (res<0) res+=mod;

        res+=paradunkcija(y-2*(x+1));
    }
    else
    {
        res=anti_dunkcija(x,y-1);
        res+=predukcija(y+y/2)-predukcija(y+x-1);
    }

    return res;
}

li pref(li n, li m)
{
    li res=(presum(n+m)-presum(n-1)-presum(m-1))%mod;
    (res+=zbirost(n,m))%=mod; if (res<0) res+=mod;

    //cout<<dunkcija(0,n)<<" "<<dunkcija(0,m)<<endl;

    if (2*n>=m) (res+=dunkcija(0,m))%=mod;
    else (res+=dunkcija(0,m)-dunkcija(n+1,m))%=mod;

    if (2*m>=n) (res+=dunkcija(0,n))%=mod;
    else (res+=dunkcija(0,n)-dunkcija(m+1,n))%=mod;

    //minus visak dole

    if (2*n>=m) (res-=anti_dunkcija(0,m))%=mod;
    else (res-=anti_dunkcija(0,m)-anti_dunkcija(n+1,m))%=mod;

    if (2*m>=n) (res-=anti_dunkcija(0,n))%=mod;
    else (res-=anti_dunkcija(0,n)-anti_dunkcija(m+1,n))%=mod;

    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

li kurac(li x)
{
    return x-(x/4)*2;
}

li podeli(li x, li y, li n, li m)
{
    li res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;

    return (res<0)?res+mod:res;

    /*fff(i,x,n) fff(j,y,m)
    {
        if (i==2 && j==2) res+=4;
        else if (j>2*i)
        {
            res+=i+kurac(j-2*i);
            res-=(i+j)/3+(i+j)%3;
        }
        else if (i>2*j)
        {
            resli fres=0;
    fff(i,x,y/2) fff(j,2*i,y)
    {
        (fres+=(i+j)/3+(i+j)%3)%=mod;
    }
    return fres;+=j+kurac(i-2*j);
            res-=(i+j)/3+(i+j)%3;
        }
    }
    return res%mod;*/
}

int main()
{
    FAST;

    li t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        li res=podeli(x,y,n,m);
        /*fff(i,x,n) fff(j,y,m)
        {
            if (j>=2*i)
            {
                res-=(i+j)/3+(i+j)%3;
                //res+=i+kurac(j-2*i);
            }
            else if (i>=2*j)
            {
                res-=(i+j)/3+(i+j)%3;
                //res+=j+kurac(i-2*j);
            }
        }*/
        if (x==2 && y==2) res+=2;
        if (res>=mod) res-=mod;
        cout<<res<<endl;
    }

    /*while (true)
    {
        int x,y; cin>>x>>y;
        cout<<"tacna vrijednost: "<<test_abdukcija(x,y)<<endl;
        cout<<"moja vrijednost:  "<<anti_dunkcija(x,y)<<endl<<endl;
    }*/

    /*while (true)
    {
        int x; cin>>x;
        cout<<paradunkcija(x)<<endl;
    }*/
}

//Note to self: Check for overflow

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return x*f;
}
inline void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
inline void Swap(int&x,int&y)
{
	x^=y^=x^=y;
}
const int mod=1e9+7,Inv2=(mod+1)/2,Inv8=(mod+1)/8,Inv24=(mod+1)/24;
int g[6][6];
inline int f1(int x)
{
	int res=0;
	if(x<3)res=0;
	else if(x&1)res=((3ll*x*x%mod*x+2ll*x*x-3ll*x-18)%mod+mod)*Inv8%mod;
	else res=((3ll*x*x%mod*x+2ll*x*x-4ll*x-16)%mod+mod)*Inv8%mod;
	return res;
}
inline int fk(int x,int y)
{
	int z=x+y,res=0,w=(x+y)/3;
	if(z%3==1)
	{
		++w;
		res=((3ll*w*w%mod*w-3ll*w*w+2ll*w)%mod+mod)*Inv2%mod;
	}
	if(z%3==0)res=((3ll*w*w%mod*w+3ll*w*w+2ll*w)%mod+mod)*Inv2%mod;
	if(z%3==2)res=((3ll*w*w%mod*w+9ll*w%mod*w+10ll*w+4)%mod+mod)*Inv2%mod;
	return res;
}
inline int f2(int x,int y)
{
	if(x>y)Swap(x,y);
	if(x<3)return 0;
	if(y<=5)return g[x][y];
	int res=(f1(x/2)+f1(y/2))%mod;
	res=(res-f2(x/2,y/2)+mod)%mod;
	res=(res+fk(x,y))%mod;
	res=(res-fk(y/2,y)+mod)%mod;
	res=(res-fk(x,x/2)+mod)%mod;
	res=(res+fk(y/2,x/2))%mod;
	return res;
}
inline int f3(int y)
{
	int d=0;
	if(~y&1)
	{
		++y;
		d=1;
	}
	int res=((2ll*y*y%mod*y-9ll*y%mod*y-26ll*y+105)%mod+mod)*Inv24%mod;
	if(d)
	{
		int q=(ll)((y-2)/4)*((y+1)/2)%mod;
		q=(q+(ll)((y-4)/4)*(y/2))%mod;
		res=(res-q+mod)%mod;
	}
	return res;
}
inline int f4(int x,int y)
{
	int res=f3(y),z=y-(x-2)*2;
	int q=f3(z),d=0;
	if(~z&1)
	{
		++z;
		d=1;
	}
	int q2=(ll)(z/2-1)*(z/2-2)%mod;
	if(d)q2=(q2-(z-5)/2+mod)%mod;
	q=(q+(ll)q2*(x-2))%mod;
	res=(res-q+mod)%mod;
	return res;
}
inline int f(int x,int y)
{
	if(x>y)Swap(x,y);
	if(x<3)return 0;
	if(x*2<=y)return((ll)f1(x)+f4(x,y)+f3(x))%mod;
	else return((ll)f2(x,y)+f3(y)+f3(x))%mod;
}
int main()
{
	g[3][3]=4;
	g[3][4]=7;
	g[3][5]=9;
	g[4][4]=12;
	g[4][5]=17;
	g[5][5]=26;
	int T=read();
	while(T--)
	{
		int X=read(),Y=read(),N=read(),M=read();
		int Ans=f(N,M);
		Ans=(Ans-f(X-1,M)+mod)%mod;
		Ans=(Ans-f(N,Y-1)+mod)%mod;
		Ans=(Ans+f(X-1,Y-1))%mod;
		write(Ans);
		puts("");
	}
	return 0;
}
/*
2
3 4 5 6
5 5 8 8
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const ll MOD = (ll)1e9 + 7;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = (int)1e9 + 2;
//const int N = 1;

ll div2down(ll c) {
	if (c >= 0) return c / 2;
	return (c - 1) / 2;
}

ll solve5(ll Y, ll c) {
	if (Y < 0) return 0;
	ll ans = mult(mult(2, Y), mult(Y + 1, 2 * Y + 1));
	while(ans % 3 != 0) ans += MOD;
	ans /= 3;
	ans = sub(0, ans);
	ans = add(ans, mult(mult(Y, Y + 1), c - 1));
	ans = add(ans, mult(Y + 1, mult(c - div2down(c), 1 - div2down(c))));
	ans %= MOD;
	if (ans < 0) ans += MOD;
	return ans;
}

ll solve4(ll X, ll Y, ll c) {
	if (X <= 0) return 0;
//	eprintf("solve4 %lld %lld %lld\n", X, Y, c);
	ll ans = 0;
	while(-4 * Y + c > 0) {
		ans += mult(X, X - 1) - mult(4, mult(Y, X)) + mult(X, c);
		Y++;
	}
//	eprintf("after while %lld %lld\n", Y, ans);
	if (2 * (X - 1) - 4 * Y + c <= 0) return ans;
	ll maxY = (2 * (X - 1) + c - 1) / 4;
	assert(maxY >= Y);
	ans += mult(mult(X, X - 1), maxY - Y + 1);
	ans -= mult(sub(mult(maxY, maxY + 1), mult(Y, Y - 1)), mult(2, X));
	ans += mult(c, mult(X, maxY - Y + 1));
	ans -= sub(solve5(maxY, c), solve5(Y - 1, c));
	ans %= MOD;
	if (ans < 0) ans += MOD;
	return ans;
}

ll solve3(ll X, ll Y, ll c) {
	if (2 * X - 4 * Y + c > 0) {
		return sub(solve4(N, Y, c), solve4(X, Y, c));
	} else {
		return solve4(N, Y, c);
	}
}

int solve2(int X, int Y, int rx, int ry) {
//	eprintf("solve2 %d %d %d %d\n", X, Y, rx, ry);
	int c1 = (rx + 1) / 2;
	if ((c1 ^ rx ^ ry) & 1) c1++;
	int c2 = (ry + 1) / 2;
	if ((c2 ^ rx ^ ry) & 1) c2++;
	int c3 = (rx + ry + 2) / 3;
	if ((c3 ^ rx ^ ry) & 1) c3++;
//	eprintf("%d %d %d\n", c1, c2, c3);
	int ans = 0;
	ans = add(ans, mult(mult(2, N - Y), sub(mult(N, N - 1), mult(X, X - 1))));
	ans = add(ans, mult(mult(2, N - X), sub(mult(N, N - 1), mult(Y, Y - 1))));
	ans = add(ans, mult(c3, mult(N - X, N - Y)));
//	eprintf("before solve3 - %d\n", ans);
	ans = add(ans, solve3(X, Y, c1 - c3));
//	eprintf("after first solve3 - %d\n", ans);
	ans = add(ans, solve3(Y, X, c2 - c3));
//	eprintf("in solve2 - %d\n", ans);
	return ans;
}

/*
int solve(int X, int Y) {
	int ans = 0;
	for (int rx = 0; rx < 12; rx++)
		for (int ry = 0; ry < 12; ry++) {
			ans = add(ans, solve2((X - rx + 11) / 12, (Y - ry + 11) / 12, rx, ry));
		}
	return ans;
}
*/

int solve(int x, int y, int n, int m, int rx, int ry) {
//	if (rx != 2 || ry != 7) return 0;
	int ans = 0;
	x = (x - rx + 11) / 12;
	y = (y - ry + 11) / 12;
	n = (n - rx + 11) / 12;
	m = (m - ry + 11) / 12;
	ans = add(ans, solve2(x, y, rx, ry));
	ans = add(ans, solve2(n, m, rx, ry));
	ans = sub(ans, solve2(x, m, rx, ry));
	ans = sub(ans, solve2(n, y, rx, ry));
	return ans;
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int t;
	scanf("%d", &t);
//	t = 1;
	while(t--) {
		int x, y, n, m;
		scanf("%d%d%d%d", &x, &y, &n, &m);
		x--;y--;
		int ans = 0;
		for (int rx = 0; rx < 12; rx++)
			for (int ry = 0; ry < 12; ry++) {
				int cur = solve(x, y, n, m, rx, ry);
				ans = add(ans, cur);
//				eprintf("rx = %d, ry = %d, cur = %d\n", rx, ry, cur);
			}
		if (x == 2 && y == 2) ans = add(ans, 2);
		printf("%d\n", ans);
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const long long MOD=1e9+7;

struct intmod {
	long long val;

	intmod operator + (const intmod other) const {
		intmod ret;
		ret.val=val+other.val;

		if (ret.val>=MOD) {
			ret.val-=MOD;
		}

		return ret;
	}

	intmod operator - (const intmod other) const {
		intmod ret;
		ret.val=val+MOD-other.val;

		if (ret.val>=MOD) {
			ret.val-=MOD;
		}

		return ret;
	}

	intmod operator * (const intmod other) const {
		intmod ret;
		ret.val=val*other.val%MOD;

		return ret;
	}
}
HALF={(MOD+1)/2}, THIRD={(MOD+1)/3};

intmod make_int(long long x) {
	return {x};
}

struct polinom {
	intmod koef[4];

	intmod ans(intmod x) {
		intmod ret;
		ret=koef[3];
		ret=(ret*x)+koef[2];
		ret=(ret*x)+koef[1];
		ret=(ret*x)+koef[0];

		return ret;
	}

	polinom sum() {
		polinom ret;

		ret.koef[0]={0};
		ret.koef[1]=koef[0]+((koef[1]+(koef[2]*THIRD))*HALF);
		ret.koef[2]=(koef[1]+koef[2])*HALF;
		ret.koef[3]=koef[2]*THIRD;

		return ret;
	}

	polinom operator + (const polinom other) const {
		polinom ret;

		ret.koef[0]=koef[0]+other.koef[0];
		ret.koef[1]=koef[1]+other.koef[1];
		ret.koef[2]=koef[2]+other.koef[2];
		ret.koef[3]=koef[3]+other.koef[3];

		return ret;
	}

	polinom operator - (const polinom other) const {
		polinom ret;

		ret.koef[0]=koef[0]-other.koef[0];
		ret.koef[1]=koef[1]-other.koef[1];
		ret.koef[2]=koef[2]-other.koef[2];
		ret.koef[3]=koef[3]-other.koef[3];

		return ret;
	}

	polinom operator * (const intmod other) const {
		polinom ret;

		ret.koef[0]=koef[0]*other;
		ret.koef[1]=koef[1]*other;
		ret.koef[2]=koef[2]*other;
		ret.koef[3]=koef[3]*other;

		return ret;
	}
}
BASE={1,3,0,0};

intmod f(long long K) {
	polinom save;
	save=BASE;
	save=save.sum();

	intmod ret;
	ret=save.ans({K/3});

	if (K%3>=1) {
		ret=ret+make_int(K/3+1);
	}

	if (K%3>=2) {
		ret=ret+make_int(K/3+2);
	}

	return ret;
}

intmod a(long long K) {
	polinom save;
	save=BASE;
	save=save.sum();
	save=save*make_int(3);
	save=save-BASE;
	save=save.sum();

	intmod ret;
	ret=save.ans({K/3});

	if (K%3>=1) {
		ret=ret+f(K);
	}

	if (K%3>=2) {
		ret=ret+f(K-1);
	}

	return ret;
}

intmod b(long long K) {
	polinom save;
	save=BASE;
	save=save.sum();
	save=save.sum();

	return save.ans({K});
}

intmod c(long long K) {
	return a(3*K/2)-b(K/2);
}

intmod d(long long K) {
	polinom save;
	save={0,5,2,0};
	save=save.sum();

	return save.ans({K});
}

intmod e(long long K) {
	polinom save;
	save={5,2,0,0};
	save=save.sum();

	return save.ans({K});
}

intmod P(long long N,long long M) {
	long long K;
	N=min(N,2*M-1);
	M=min(M,2*N-1);
	K=max(3LL,M/2);

	if (N<=3) {
		return {0};
	}

	intmod ret;
	ret=a(N+M-2)-a(M+K-2);
	ret=ret+b(K-1)-b(2);
	ret=ret-c(N-1)+c(2);

	return ret;
}

intmod Q(long long N,long long M) {
	N=min(N,M/2)-2;
	M=M-5;

	if (N<=0) {
		return {0};
	}

	intmod ret;
	ret=d(N-1);
	ret=ret+((e(M/2)-e(N-1))*make_int(N));

	if (M%2>=1) {
		ret=ret+(make_int(N/2)*make_int(M+6));

		if (N%2>=1) {
			ret=ret+make_int(2*((M+1)/4)+3);
		}
	}

	return ret;
}

intmod area(long long N,long long M) {
	if (N<3) {
		return {0};
	}

	intmod ret;
	ret={0};

	for (long long i=3;i<=5;i++) {
		if (i<=M) {
			ret=ret+make_int(7-i);
		}
	}

	ret=ret+P(N,M);
	ret=ret+Q(N,M);
	ret=ret+Q(M,N);

	return ret;
}

long long Nmin, Mmin;
long long Nmax, Mmax;
intmod ans;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	long long tc;
	cin>>tc;
	while(tc--) {
		cin>>Nmin>>Mmin;
		cin>>Nmax>>Mmax;

		ans=area(Nmax,Mmax)+area(Nmin-1,Mmin-1);
		ans=ans-(area(Nmax,Mmin-1)+area(Nmin-1,Mmax));

		cout<<ans.val<<'\n';
	}
	return 0;
}

#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<cstdio>
#define rg register
#define R(i,a,n) for(register long long i=(a);i<=(n);i++)
#define F(i,a,n) for(register long long i=(n);i>=(a);i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> void read(T &x) {
	x = 0; int f = 0; char ch = getchar();
	while (ch < '0' || ch > '9') {f |= (ch == '-'); ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();}
	x = f ? -x : x;
	return;
}
using namespace std;

const long long MOD=1e9+7;

struct intmod {
	long long val;

	intmod operator + (const intmod other) const {
		intmod ret;
		ret.val=val+other.val;

		if (ret.val>=MOD) {
			ret.val-=MOD;
		}

		return ret;
	}

	intmod operator - (const intmod other) const {
		intmod ret;
		ret.val=val+MOD-other.val;

		if (ret.val>=MOD) {
			ret.val-=MOD;
		}

		return ret;
	}

	intmod operator * (const intmod other) const {
		intmod ret;
		ret.val=val*other.val%MOD;

		return ret;
	}
}
HALF={(MOD+1)/2}, THIRD={(MOD+1)/3};

intmod make_int(long long x) {
	return {x};
}

struct polinom {
	intmod koef[4];

	intmod ans(intmod x) {
		intmod ret;
		ret=koef[3];
		ret=(ret*x)+koef[2];
		ret=(ret*x)+koef[1];
		ret=(ret*x)+koef[0];

		return ret;
	}

	polinom sum() {
		polinom ret;

		ret.koef[0]={0};
		ret.koef[1]=koef[0]+((koef[1]+(koef[2]*THIRD))*HALF);
		ret.koef[2]=(koef[1]+koef[2])*HALF;
		ret.koef[3]=koef[2]*THIRD;

		return ret;
	}

	polinom operator + (const polinom other) const {
		polinom ret;

		ret.koef[0]=koef[0]+other.koef[0];
		ret.koef[1]=koef[1]+other.koef[1];
		ret.koef[2]=koef[2]+other.koef[2];
		ret.koef[3]=koef[3]+other.koef[3];

		return ret;
	}

	polinom operator - (const polinom other) const {
		polinom ret;

		ret.koef[0]=koef[0]-other.koef[0];
		ret.koef[1]=koef[1]-other.koef[1];
		ret.koef[2]=koef[2]-other.koef[2];
		ret.koef[3]=koef[3]-other.koef[3];

		return ret;
	}

	polinom operator * (const intmod other) const {
		polinom ret;

		ret.koef[0]=koef[0]*other;
		ret.koef[1]=koef[1]*other;
		ret.koef[2]=koef[2]*other;
		ret.koef[3]=koef[3]*other;

		return ret;
	}
}
BASE={1,3,0,0};

intmod f(long long K) {
	polinom save;
	save=BASE;
	save=save.sum();

	intmod ret;
	ret=save.ans({K/3});

	if (K%3>=1) {
		ret=ret+make_int(K/3+1);
	}

	if (K%3>=2) {
		ret=ret+make_int(K/3+2);
	}

	return ret;
}

intmod a(long long K) {
	polinom save;
	save=BASE;
	save=save.sum();
	save=save*make_int(3);
	save=save-BASE;
	save=save.sum();

	intmod ret;
	ret=save.ans({K/3});

	if (K%3>=1) {
		ret=ret+f(K);
	}

	if (K%3>=2) {
		ret=ret+f(K-1);
	}

	return ret;
}

intmod b(long long K) {
	polinom save;
	save=BASE;
	save=save.sum();
	save=save.sum();

	return save.ans({K});
}

intmod c(long long K) {
	return a(3*K/2)-b(K/2);
}

intmod d(long long K) {
	polinom save;
	save={0,5,2,0};
	save=save.sum();

	return save.ans({K});
}

intmod e(long long K) {
	polinom save;
	save={5,2,0,0};
	save=save.sum();

	return save.ans({K});
}

intmod P(long long N,long long M) {
	long long K;
	N=min(N,2*M-1);
	M=min(M,2*N-1);
	K=max(3LL,M/2);

	if (N<=3) {
		return {0};
	}

	intmod ret;
	ret=a(N+M-2)-a(M+K-2);
	ret=ret+b(K-1)-b(2);
	ret=ret-c(N-1)+c(2);

	return ret;
}

intmod Q(long long N,long long M) {
	N=min(N,M/2)-2;
	M=M-5;

	if (N<=0) {
		return {0};
	}

	intmod ret;
	ret=d(N-1);
	ret=ret+((e(M/2)-e(N-1))*make_int(N));

	if (M%2>=1) {
		ret=ret+(make_int(N/2)*make_int(M+6));

		if (N%2>=1) {
			ret=ret+make_int(2*((M+1)/4)+3);
		}
	}

	return ret;
}

intmod area(long long N,long long M) {
	if (N<3) {
		return {0};
	}

	intmod ret;
	ret={0};

	for (long long i=3;i<=5;i++) {
		if (i<=M) {
			ret=ret+make_int(7-i);
		}
	}

	ret=ret+P(N,M);
	ret=ret+Q(N,M);
	ret=ret+Q(M,N);

	return ret;
}

long long Nmin, Mmin;
long long Nmax, Mmax;
intmod ans;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	long long tc;
	cin>>tc;
	while(tc--) {
		cin>>Nmin>>Mmin;
		cin>>Nmax>>Mmax;

		ans=area(Nmax,Mmax)+area(Nmin-1,Mmin-1);
		ans=ans-(area(Nmax,Mmin-1)+area(Nmin-1,Mmax));

		cout<<ans.val<<'\n';
	}
	return 0;
}

#include <bits/stdc++.h>

inline int read() {
    char c; int x; for (c = getchar(); !isdigit(c); c = getchar());
    for (x = 0; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } return x;
}

const int mod = 1e9 + 7;

const int dx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int dy[8] = {2, -2, 2, -2, 1, -1, 1, -1};

const int N = 105;

int f[N][N];

long long solve1(long long n, long long m) {
    if (n % 2 == 0) {
        long long res = solve1(n - 1, m);
        m = std::min(n / 2, m);
        long long x = n / 2 % 2 ? n / 2 : n / 2 + 1;
        long long y = n / 2 % 2 ? n / 2 + 1 : n / 2;
        res += x * ((m + 1) / 2) + y * (m / 2);
        return res;
    }
    n /= 2;
    long long res = 0;
    if (n <= m) {
        res += n * (n + 1) * (n * 4 + 5) / 6;
    } else {
        res += m * (m + 1) * (m * 4 + 5) / 6;
        res -= m * (m + 1) * (m + 1);
        res += m * (n + 1) * (n + 1);
    }
    return res;
}

long long solve2(long long n, long long m) {
    long long res = std::min((n - 1) / 2, m - 1);
    res = res * (res + 1) / 2;
    return res;
}
long long solve3(long long n, long long m) {
    long long res;
    n = std::min(n, m) - 1;
    res = (4 + n * n * 3 + n * 9 + (n % 3 - (n - 1) % 3) * 2) / 18;
    return res * 2;
}
long long check(long long n, long long m) {
    long long res = 0;
    for (long long l = 1, r = 1e9, mid; l <= r; ) {
        mid = (l + r) / 2;
        if (std::min(mid, m - mid - mid) > std::max((long long) 0, mid * 4 - n)) {
            l = mid + 1; res = mid;
        } else {
            r = mid - 1;
        }
    }
    return res;
}
long long solve4(long long n, long long m) {
    long long res = 0, p = check(n, m);
    if (p == 0) { return 0; }
    long long pn = n / 4, pm = m / 3;
    pn = std::min(pn, p); pm = std::min(pm, p);
    if (pn > pm) {
        res += pm * (pm + 1) * (pm * 4 + 5) / 6;
        res -= m * (pm + 1) * (pm + 1) - (pm * (pm + 1) * (pm * 4 + 5) / 6 * 2);
        res += m * (pn + 1) * (pn + 1) - (pn * (pn + 1) * (pn * 4 + 5) / 6 * 2);
        res -= (m + n) * (pn + 1) * (pn + 1) - (pn * (pn + 1) * (pn * 4 + 5) / 6 * 6);
        res += (m + n) * (p + 1) * (p + 1) - (p * (p + 1) * (p * 4 + 5) / 6 * 6);
    } else {
        res += pn * (pn + 1) * (pn * 4 + 5) / 6;
        res -= n * (pn + 1) * (pn + 1) - (pn * (pn + 1) * (pn * 4 + 5) / 6 * 3);
        res += n * (pm + 1) * (pm + 1) - (pm * (pm + 1) * (pm * 4 + 5) / 6 * 3);
        res -= (m + n) * (pm + 1) * (pm + 1) - (pm * (pm + 1) * (pm * 4 + 5) / 6 * 6);
        res += (m + n) * (p + 1) * (p + 1) - (p * (p + 1) * (p * 4 + 5) / 6 * 6);
    }
    return res;
}
long long solve5(long long n, long long m) {
    n -= 2; m -= 1;
    if (n < 1 || m < 1) { return 0; }
    long long res = 0, p = check(n, m);
    if (p == 0) { return 0; }
    long long pn = n / 4, pm = m / 3;
    pn = std::min(pn, p); pm = std::min(pm, p);
    if (pn > pm) {
        res += pm * (pm + 1) * (pm * 4 + 5) / 6;
        res += pm * (pm + 1) / 2;
        res -= m * (pm + 1) * (pm + 1) - (pm * (pm + 1) * (pm * 4 + 5) / 6 * 2);
        res -= pm * m - pm * (pm + 1) / 2 * 2;
        res += m * (pn + 1) * (pn + 1) - (pn * (pn + 1) * (pn * 4 + 5) / 6 * 2);
        res += pn * m - pn * (pn + 1) / 2 * 2;
        res -= (m + n) * (pn + 1) * (pn + 1) - (pn * (pn + 1) * (pn * 4 + 5) / 6 * 6);
        res -= pn * (n + m) - pn * (pn + 1) / 2 * 6;
        res += (m + n) * (p + 1) * (p + 1) - (p * (p + 1) * (p * 4 + 5) / 6 * 6);
        res += p * (n + m) - p * (p + 1) / 2 * 6;
    } else {
        res += pn * (pn + 1) * (pn * 4 + 5) / 6;
        res += pn * (pn + 1) / 2;
        res -= n * (pn + 1) * (pn + 1) - (pn * (pn + 1) * (pn * 4 + 5) / 6 * 3);
        res -= pn * n - pn * (pn + 1) / 2 * 3;
        res += n * (pm + 1) * (pm + 1) - (pm * (pm + 1) * (pm * 4 + 5) / 6 * 3);
        res += pm * n - pm * (pm + 1) / 2 * 3;
        res -= (m + n) * (pm + 1) * (pm + 1) - (pm * (pm + 1) * (pm * 4 + 5) / 6 * 6);
        res -= pm * (n + m) - pm * (pm + 1) / 2 * 6;
        res += (m + n) * (p + 1) * (p + 1) - (p * (p + 1) * (p * 4 + 5) / 6 * 6);
        res += p * (n + m) - p * (p + 1) / 2 * 6;
    }
    return res;
}

long long solve(long long n, long long m) {
    if (n == 0 || m == 0) { return 0; }
    long long res = 0;
    res += solve1(n, m) + solve1(m, n);
    res += solve2(n, m) + solve2(m, n);
    res += solve3(n, m);
    res += solve4(n, m) + solve4(m, n);
    res += solve4(n - 1, m - 1) + solve4(m - 1, n - 1);
    res += solve4(n - 2, m - 2) + solve4(m - 2, n - 2);
    res += solve5(n, m) + solve5(m, n);
    res += solve5(n - 1, m - 1) + solve5(m - 1, n - 1);
    res += solve5(n - 2, m - 2) + solve5(m - 2, n - 2);
    if (1 <= n && 2 <= m) { res += 2; }
    if (2 <= n && 1 <= m) { res += 2; }
    if (2 <= n && 2 <= m) { res += 2; }
    if (3 <= n && 3 <= m) { res += 2; }
    return res;
}

int main() {
    for (int T = read(); T; T--) {
        int r = read(), c = read(), n = read(), m = read();
        if (n <= 50 && m <= 50) {
            memset(f, 60, sizeof(f));
            f[1][1] = 0;
            for (int d = 0; d < 100; d++) {
                for (int i = 1; i <= n; i++) {
                    for (int j = 1; j <= m; j++) {
                        for (int k = 0; k < 8; k++) {
                            int x = i + dx[k], y = j + dy[k];
                            if (1 <= x && 1 <= y && x <= n && y <= m) {
                                f[i][j] = std::min(f[i][j], f[x][y] + 1);
                            }
                        }
                    }
                }
            }
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if (f[i][j] > 1e9) { f[i][j] = 0; }
                    f[i][j] += f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1];
                }
            }
            printf("%d\n", f[n][m] + f[r - 1][c - 1] - f[n][c - 1] - f[r - 1][m]);
        } else {
            printf("%d\n", (int) ((solve(n, m) + solve(r - 1, c - 1) - solve(n, c - 1) - solve(r - 1, m)) % mod));
        }
    }
    return 0;
}

#include <cstdio>
const int MOD = 1000000007;
const int inv2 = 500000004;
const int inv3 = 333333336;
const int inv4 = 250000002;
const int inv6 = 166666668;
const int inv72 = 13888889;
const int magic3[3] = {0, -32, -16};
const int magic6[6] = {-16, 36, -32, 20, 0, 4};

int _add(int x) { return x < MOD ? x : x - MOD; }
int add(int x, int y) { return _add(x + y); }
int _sub(int x) { return x < 0 ? x + MOD : x; }
int sub(int x, int y) { return _sub(x - y); }
int mul(int x, int y) { return 1LL * x * y % MOD; }

int f4(int x)
{
    int res = mul(x + 6, mul(x, x));
    if (x % 2 == 0)
        res = add(res, MOD + magic3[x / 2 % 3]);
    else
        res = add(res, add(mul(9, x), MOD + magic6[(x - 1) / 2 % 6]));
    res = mul(inv72, res);
    return res;
}

int f3(int x, int y)
{
    int res = mul(inv6, mul(add(x, y) + 4, mul(x + 1, y + 1)));
    if (x % 3 == 0 || y % 3 == 0)
        res = sub(res, mul(inv3, 2));
    return res;
}

int f2(int x, int y)
{
    int res = mul(inv4, mul(y + 1, mul(x, x + 4)));
    if (x % 2 == 1)
    {
        res = add(res, mul(inv4, y + 1));
        if (y % 2 == 0)
            if (x % 4 == 1)
                res = sub(res, inv2);
            else
                res = add(res, inv2);
    }
    return res;
}

int f(int x, int y)
{
    if (x < y)
        return f(y, x);
    int res = 0;
    if (y < x / 2)
    {
        res = add(res, f2(x, y));
        x = y * 2;
        res = sub(res, f2(x, y));
    }
    res = add(res, add(f3(x, y), add(f4(x), f4(y))));
    return res;
}

int solve()
{
    int x, y, n, m; scanf("%d%d%d%d", &x, &y, &n, &m);
    --x; --y; --n; --m;
    --x; --y;
    int res = sub(add(f(n, m), f(x, y)), add(f(x, m), f(n, y)));
    if (x == 1 && y == 1)
        res = add(res, 2);
    return res;
}

int main()
{
    int t; scanf("%d", &t);
    for (int i = 1; i <= t; ++i)
        printf("%d\n", solve());
}

#include <cstdio>
#include <algorithm>

typedef long long LL;
const int Mod = 1000000007;
const int Inv2 = (Mod + 1) / 2;
const int Inv8 = (Mod + 1) / 8;
const int Inv24 = (Mod + 1) / 24;

int g[6][6];
inline int f1(int x) {
	int ret = 0;
	if (x < 3) ret = 0;
	else if (x & 1) ret = ((3ll * x * x % Mod * x + 2ll * x * x - 3ll * x - 18) % Mod + Mod) * Inv8 % Mod;
	else ret = ((3ll * x * x % Mod * x + 2ll * x * x - 4ll * x - 16) % Mod + Mod) * Inv8 % Mod;
//	printf("f1(%d) = %d\n", x, ret);
	return ret;
}
inline int fk(int x, int y) {
	int z = x + y, ret = 0;
	int w = z / 3;
	if (z % 3 == 1) ++w, ret = ((3ll * w * w % Mod * w - 3ll * w * w + 2ll * w) % Mod + Mod) * Inv2 % Mod;
	if (z % 3 == 0) ret = ((3ll * w * w % Mod * w + 3ll * w * w + 2ll * w) % Mod + Mod) * Inv2 % Mod;
	if (z % 3 == 2) ret = ((3ll * w * w % Mod * w + 9ll * w % Mod * w + 10ll * w + 4) % Mod + Mod) * Inv2 % Mod;
//	printf("fk(%d, %d) = %d\n", x, y, ret);
	return ret;
}
int f2(int x, int y) {
	if (x > y) std::swap(x, y);
	if (x < 3) return 0;
	if (y <= 5) return g[x][y];
	int ret = (f1(x / 2) + f1(y / 2)) % Mod;
	ret = (ret - f2(x / 2, y / 2) + Mod) % Mod;
	ret = (ret + fk(x, y)) % Mod;
	ret = (ret - fk(y / 2, y) + Mod) % Mod;
	ret = (ret - fk(x, x / 2) + Mod) % Mod;
	ret = (ret + fk(y / 2, x / 2)) % Mod;
//	printf("f2(%d, %d) = %d\n", x, y, ret);
	return ret;
}
inline int f3(int y) {
	int d = 0;
	if (~y & 1) ++y, d = 1;
	int ret = ((2ll * y * y % Mod * y - 9ll * y % Mod * y - 26ll * y + 105) % Mod + Mod) * Inv24 % Mod;
	if (d) {
		int q = (LL)((y - 2) / 4) * ((y + 1) / 2) % Mod;
		q = (q + (LL)((y - 4) / 4) * (y / 2)) % Mod;
		ret = (ret - q + Mod) % Mod;
	}
//	printf("f3(%d) = %d\n", y - d, ret);
	return ret;
}
inline int f4(int x, int y) {
	int ret = f3(y);
	int z = y - (x - 2) * 2;
	int q = f3(z);
	int d = 0;
	if (~z & 1) ++z, d = 1;
	int q2 = (LL)(z / 2 - 1) * (z / 2 - 2) % Mod;
	if (d) q2 = (q2 - (z - 5) / 2 + Mod) % Mod;
	q = (q + (LL)q2 * (x - 2)) % Mod;
	ret = (ret - q + Mod) % Mod;
//	printf("f4(%d, %d) = %d\n", x, y, ret);
	return ret;
}
inline int f(int x, int y) {
	if (x > y) std::swap(x, y);
	if (x < 3) return 0;
	if (x * 2 <= y) return (f1(x) + f4(x, y)) % Mod;
	else return ((LL)f2(x, y) + f3(y) + f3(x)) % Mod;
}

int main() {
	g[3][3] = 4;
	g[3][4] = 7;
	g[3][5] = 9;
	g[4][4] = 12;
	g[4][5] = 17;
	g[5][5] = 26;
	int Tests;
	scanf("%d", &Tests);
	while (Tests--) {
		int X, Y, N, M;
		scanf("%d%d%d%d", &X, &Y, &N, &M);
		int Ans = f(N, M);
		Ans = (Ans - f(X - 1, M) + Mod) % Mod;
		Ans = (Ans - f(N, Y - 1) + Mod) % Mod;
		Ans = (Ans + f(X - 1, Y - 1)) % Mod;
		printf("%d\n", Ans);
	}
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

using namespace __gnu_pbds;
template <class T> using oset = tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using omset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

int kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

int zbirost(li x, li y, li n, li m)
{
    li ostatak=(n-x+1)*(m-y+1)%3;
    li res=0;

    if (ostatak==1) res+=(x+y)%3;
    else if (ostatak==2) res+=(x+y)%3+(x+y-1)%3;

    res+=(n-x+1)*(m-y+1)/3*3;

    return res%mod;
}

int summ(int x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

int presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

int pref(int n, int m)
{
    int res=(presum(n+m)-presum(n-1)-presum(m))%mod;
    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

int podeli(li x, li y, li n, li m)
{
    //int res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;
    //return (res<0)?res+mod:res;

    li res=0;
    fff(i,x,n) fff(j,y,m) res+=(i+j)/3+(i+j)%3;
    return res%mod;
}

int main()
{
    FAST;

    int t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        int res=podeli(x,y,n,m);
        if (x==2&&y==2) res+=2;
        cout<<podeli(x,y,n,m)<<endl;
    }

    //ff(i,0,15) cout<<summ(i)<<" "; cout<<endl;
    //ff(i,0,9) cout<<presum(i)<<" "; cout<<endl;

    /*while (true)
    {
        int x; cin>>x;
        cout<<","<<presum(x)<<endl;
    }*/
}

//Note to self: Check for overflow

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

using namespace __gnu_pbds;
template <class T> using oset = tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using omset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

int kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

int zbirost(li x, li y, li n, li m)
{
    li ostatak=(n-x+1)*(m-y+1)%3;
    li res=0;

    if (ostatak==1) res+=(x+y)%3;
    else if (ostatak==2) res+=(x+y)%3+(x+y-1)%3;

    res+=(n-x+1)*(m-y+1)/3*3;

    return res%mod;
}

int summ(int x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

int presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

int pref(int n, int m)
{
    int res=(presum(n+m)-presum(n-1)-presum(m))%mod;
    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

int kurac(int x)
{
    return x-(x/4)*2;
}

int podeli(li x, li y, li n, li m)
{
    //int res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;
    //return (res<0)?res+mod:res;

    li res=0;
    fff(i,x,n) fff(j,y,m)
    {
        if (x==2 && y==2) res+=4;
        else if(x<=2*y && y<=2*x) res+=(i+j)/3+(i+j)%3;
        else if (y>2*x) res+=i+kurac(j-i);
        else res+=j+kurac(j-i);
    }
    return res%mod;
}

int main()
{
    FAST;

    int t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        int res=podeli(x,y,n,m);
        cout<<res<<endl;
    }

    //ff(i,0,15) cout<<summ(i)<<" "; cout<<endl;
    //ff(i,0,9) cout<<presum(i)<<" "; cout<<endl;

    /*while (true)
    {
        int x; cin>>x;
        cout<<","<<presum(x)<<endl;
    }*/
}

//Note to self: Check for overflow

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

using namespace __gnu_pbds;
template <class T> using oset = tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using omset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

int kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

int zbirost(li x, li y)
{
    x++; y++;
    if (x%3==0 || y%3==0) return x*y/3*3;
    if (x%3==1 && y%3==1) return x*y/3*3 + (x+y-2)%3;
    if (x%3==2 && y%3==2) return x*y/3*3 - 3 + (x+y-2)%3 + (x+y-3)%3 + (x+y-3)%3 + (x+y-4)%3;
    else return x*y/3*3 + (x+y-2)%3 + (x+y-3)%3;
}

int summ(int x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

int presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

li presumsum(li x)
{
    return x*(x+1)%mod*(x+2)%mod*inv(6)%mod;
}

li oduzm_red(int p, int k)
{
    //(sum(p) + sum(p+1) + sum(p+2) + sum(p+3)) + (sum(p+2)+sum(p+3)+sum(p+4)+sum(p+5)) + ...
    //suma prvih k+1 elem.  blokovi su mod 4

    int kk=(k/4*4+3)/2+2;
    li res=presumsum(p+kk)+presumsum(p+kk-2)-presumsum(p+1)-presumsum(p-1);
    if (k%4<=2) (res-=sum(p+kk))%=mod;
    if (k%4<=1) (res-=sum(p+kk-1))%=mod;
    if (k%4<=0) (res-=sum(p+kk-2))%=mod;
    if (res<0) res+=mod;

    //cout<<p<<" "<<k<<" "<<kk<<": "<<res<<endl;
    return res;
}

int dunkcija(int x, int y)
{
    if (2*x>y) return 0;

    li res=0;
    if (y%2==0)
    {
        int fakex=y/2; //cout<<fakex<<" "<<x<<": ";
        res+=(fakex-x+1)*(sum(fakex)%mod)+(fakex-x)*(sum(fakex+1)%mod);
        res-=oduzm_red(x-1,y-2*x); if (res<0) res+=mod;

        return res;
    }
    else
    {
        res=dunkcija(x,y-1);
        li fakex=y/2+1;

        res+=(fakex-x)*fakex+fakex/2;
        if (y%4==1) res-=x/2;
        else res-=(x+1)/2;
        return res%mod;
    }
}

int predukcija(int x)
{
    //racuna prefiksnu sumu za prvih x+1 elemenata eledeceg niza: 0,1,2,1,2,3,2,3,4,3,4,5,4,5,6,5,6,7,...

    int res = sum(x);
    res-=6*sum(x/3);

    //cout<<sum(x)<<"-"<<6*sum(x/3)<<" = ";

    if (x%3<=1) res+=2*(x/3);
    if (x%3<=0) res+=2*(x/3);

    res%=mod; if (res<0) res+=mod;

    //cout<<x<<": "<<res<<endl;

    return res;
}

int redunkcija(li k)
{
    k--;
    return ((k+1)*9+(li)presumsum(k)*12)%mod;
}

int paradunkcija(int x)
{
    //neka je p predukcija skraceno
    //racuna p(1)+p(3)+p(5)+...+p(x), x je garantovano neparno

    //suma po modovima hahahahhaha
    //tacnije, p(1) + p(7) + p(13) + ... itd za ostale kurceve

    if (x==0) return 0;
    if (x==1) return 1;
    if (x==3) return 5;
    if (x==5) return 14;

    li mod5 = redunkcija((x+1)/6);
    li mod1 = redunkcija((x-1)/6)+4ll*((x-1)/6);
    li mod3 = redunkcija((x-3)/6)+8ll*((x-3)/6);

    mod1+=((x-1)/6+1);
    mod3+=4ll*((x-3)/6+1);

    /*cout<<"baza: "<<redunkcija((x-3)/6)<<endl;
    cout<<"dodatak na bazu: 4 puta " << 2ll*((x-3)/6)<<endl;
    cout<<"dodatni kurac: "<<4ll*((x-3)/6+1)<<endl;
    cout<<"ukupno: "<<mod3<<endl<<endl;*/

    return ((mod1%mod + mod5%mod)%mod + mod3%mod)%mod;

    return 0;

    /*int res=0;
    for (int i=1;i<=x;i+=2) (res+=predukcija(i))%=mod;

    return res;*/
}

int anti_dunkcija(int x, int y)
{
    if (2*x>y) return 0;

    li fx=y/2,res=-69420;
    if (y%2==1)
    {
        x--;
        res=(fx-x)*(fx-x+1)%mod*(fx+1)%mod - 2*kvsum(fx-x);
        if (res<0) res+=mod; if (res<0) res+=mod;

        res+=paradunkcija(y-2*(x+1));
    }
    else
    {
        res=anti_dunkcija(x,y-1);
        res+=predukcija(y+y/2)-predukcija(y+x-1);
    }

    return res;
}

int pref(int n, int m)
{
    int res=(presum(n+m)-presum(n-1)-presum(m-1))%mod;
    (res+=zbirost(n,m))%=mod; if (res<0) res+=mod;

    //cout<<dunkcija(0,n)<<" "<<dunkcija(0,m)<<endl;

    if (2*n>=m) (res+=dunkcija(0,m))%=mod;
    else (res+=dunkcija(0,m)-dunkcija(n+1,m))%=mod;

    if (2*m>=n) (res+=dunkcija(0,n))%=mod;
    else (res+=dunkcija(0,n)-dunkcija(m+1,n))%=mod;

    //minus visak dole

    if (2*n>=m) (res-=anti_dunkcija(0,m))%=mod;
    else (res-=anti_dunkcija(0,m)-anti_dunkcija(n+1,m))%=mod;

    if (2*m>=n) (res-=anti_dunkcija(0,n))%=mod;
    else (res-=anti_dunkcija(0,n)-anti_dunkcija(m+1,n))%=mod;

    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

int kurac(int x)
{
    return x-(x/4)*2;
}

int podeli(li x, li y, li n, li m)
{
    int res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;

    return (res<0)?res+mod:res;

    /*fff(i,x,n) fff(j,y,m)
    {
        if (i==2 && j==2) res+=4;
        else if (j>2*i)
        {
            res+=i+kurac(j-2*i);
            res-=(i+j)/3+(i+j)%3;
        }
        else if (i>2*j)
        {
            res+=j+kurac(i-2*j);
            res-=(i+j)/3+(i+j)%3;
        }
    }
    return res%mod;*/
}

int main()
{
    FAST;

    int t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        int res=podeli(x,y,n,m);
        /*fff(i,x,n) fff(j,y,m)
        {
            if (j>=2*i)
            {
                res-=(i+j)/3+(i+j)%3;
                //res+=i+kurac(j-2*i);
            }
            else if (i>=2*j)
            {
                res-=(i+j)/3+(i+j)%3;
                //res+=j+kurac(i-2*j);
            }
        }*/
        if (x==2 && y==2) res+=2;
        if (res>=mod) res-=mod;
        cout<<res<<endl;
    }

    /*while (true)
    {
        int x,y; cin>>x>>y;
        cout<<anti_dunkcija(x,y)<<endl;
    }*/

    /*while (true)
    {
        int x; cin>>x;
        cout<<paradunkcija(x)<<endl;
    }*/
}

//Note to self: Check for overflow

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

using namespace __gnu_pbds;
template <class T> using oset = tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using omset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

int kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

int zbirost(li x, li y)
{
    x++; y++;
    if (x%3==0 || y%3==0) return x*y/3*3;
    if (x%3==1 && y%3==1) return x*y/3*3 + (x+y-2)%3;
    if (x%3==2 && y%3==2) return x*y/3*3 - 3 + (x+y-2)%3 + (x+y-3)%3 + (x+y-3)%3 + (x+y-4)%3;
    else return x*y/3*3 + (x+y-2)%3 + (x+y-3)%3;
}

int summ(int x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

int presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

int pref(int n, int m)
{
    int res=(presum(n+m)-presum(n-1)-presum(m-1))%mod;
    (res+=zbirost(n,m))%=mod;
    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

int kurac(int x)
{
    return x-(x/4)*2;
}

int podeli(li x, li y, li n, li m)
{
    int res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;
    return (res<0)?res+mod:res;

    /*li res=0;
    fff(i,x,n) fff(j,y,m)
    {
        if (i==2 && j==2) res+=4;
        else if (j>2*i) res+=i+kurac(j-2*i);
        else if (i>2*j) res+=j+kurac(i-2*j);
        else res+=(i+j)/3+(i+j)%3;
    }
    return res%mod;*/
}

int main()
{
    FAST;

    int t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        int res=podeli(x,y,n,m);
        fff(i,x,n) fff(j,y,m)
        {
            if (j>=2*i) res+=i+kurac(j-2*i)-(i+j)/3-(i+j)%3;
            else if (i>=2*j) res+=j+kurac(i-2*j)-(i+j)/3-(i+j)%3;
        }
        cout<<res<<endl;
    }

    /*while (true)
    {
        int x,y; cin>>x>>y;
        cout<<pref(x,y)<<endl;
    }*/
}

//Note to self: Check for overflow

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

using namespace __gnu_pbds;
template <class T> using oset = tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using omset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

int kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

int zbirost(li x, li y, li n, li m)
{
    li ostatak=(n-x+1)*(m-y+1)%3;
    li res=0;

    if (ostatak==1) res+=(x+y)%3;
    else if (ostatak==2) res+=(x+y)%3+(x+y-1)%3;

    res+=(n-x+1)*(m-y+1)/3*3;

    return res%mod;
}

int summ(int x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

int presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

int pref(int n, int m)
{
    int res=(presum(n+m)-presum(n-1)-presum(m))%mod;
    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

int podeli(li x, li y, li n, li m)
{
    int res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;
    return (res<0)?res+mod:res;
}

int fake_value(int x, int y)
{
    return (x+y)/3+(x+y)%3;
}

int real_value(int x, int y)
{
    if (x==2 && y==2) return 4;
    if (x==2 && y==3) return 3;
    if (x==3 && y==2) return 3;
    return fake_value(x,y);
}

int main()
{
    FAST;

    int t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        int res=zbirost(x,y,n,m);
        res+=podeli(x,y,n,m);

        if (x<=2 && y<=2) res+=real_value(2,2)-fake_value(2,2);
        if (x<=2 && y<=3) res+=real_value(2,3)-fake_value(2,3);
        if (x<=3 && y<=2) res+=real_value(3,2)-fake_value(3,2);

        cout<<res%mod<<endl;
    }

    //ff(i,0,15) cout<<summ(i)<<" "; cout<<endl;
    //ff(i,0,9) cout<<presum(i)<<" "; cout<<endl;

    /*while (true)
    {
        int x; cin>>x;
        cout<<","<<presum(x)<<endl;
    }*/
}

//Note to self: Check for overflow

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

using namespace __gnu_pbds;
template <class T> using oset = tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using omset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

int kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

int zbirost(li x, li y, li n, li m)
{
    li ostatak=(n-x+1)*(m-y+1)%3;
    li res=0;

    if (ostatak==1) res+=(x+y)%3;
    else if (ostatak==2) res+=(x+y)%3+(x+y-1)%3;

    res+=(n-x+1)*(m-y+1)/3*3;

    return res%mod;
}

int summ(int x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

int presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

int pref(int n, int m)
{
    int res=(presum(n+m)-presum(n-1)-presum(m))%mod;
    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

int podeli(li x, li y, li n, li m)
{
    int res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;
    return (res<0)?res+mod:res;
}

int main()
{
    FAST;

    int t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        int res=zbirost(x,y,n,m);
        res+=podeli(x,y,n,m);

        cout<<res%mod<<endl;
    }

    //ff(i,0,15) cout<<summ(i)<<" "; cout<<endl;
    //ff(i,0,9) cout<<presum(i)<<" "; cout<<endl;

    /*while (true)
    {
        int x; cin>>x;
        cout<<","<<presum(x)<<endl;
    }*/
}

//Note to self: Check for overflow

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

using namespace __gnu_pbds;
template <class T> using oset = tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using omset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

int kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

int zbirost(li x, li y, li n, li m)
{
    li ostatak=(n-x+1)*(m-y+1)%3;
    li res=0;

    if (ostatak==1) res+=(x+y)%3;
    else if (ostatak==2) res+=(x+y)%3+(x+y-1)%3;

    res+=(n-x+1)*(m-y+1)/3*3;

    return res%mod;
}

int summ(int x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

int presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

int pref(int n, int m)
{
    int res=(presum(n+m)-presum(n-1)-presum(m))%mod;
    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

int kurac(int x)
{
    return x-(x/4)*2;
}

int podeli(li x, li y, li n, li m)
{
    //int res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;
    //return (res<0)?res+mod:res;

    li res=0;
    fff(i,x,n) fff(j,y,m)
    {
        if (i==2 && j==2) res+=4;
        else if(i<=2*j && j<=2*i) res+=(i+j)/3+(i+j)%3;
        else if (j>2*i) res+=i*(j-i+1)+kurac(j-i);
        else res+=j*(i-j+1)+kurac(i-j);
    }
    return res%mod;
}

int main()
{
    FAST;

    int t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        int res=podeli(x,y,n,m);
        cout<<res<<endl;
    }

    //ff(i,0,15) cout<<summ(i)<<" "; cout<<endl;
    //ff(i,0,9) cout<<presum(i)<<" "; cout<<endl;

    /*while (true)
    {
        int x; cin>>x;
        cout<<","<<presum(x)<<endl;
    }*/
}

//Note to self: Check for overflow

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int> > typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

int kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

int zbirost(li x, li y)
{
    x++; y++;
    if (x%3==0 || y%3==0) return x*y/3*3;
    if (x%3==1 && y%3==1) return x*y/3*3 + (x+y-2)%3;
    if (x%3==2 && y%3==2) return x*y/3*3 - 3 + (x+y-2)%3 + (x+y-3)%3 + (x+y-3)%3 + (x+y-4)%3;
    else return x*y/3*3 + (x+y-2)%3 + (x+y-3)%3;
}

int summ(int x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

int presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

li presumsum(li x)
{
    return x*(x+1)%mod*(x+2)%mod*inv(6)%mod;
}

li oduzm_red(int p, int k)
{
    //(sum(p) + sum(p+1) + sum(p+2) + sum(p+3)) + (sum(p+2)+sum(p+3)+sum(p+4)+sum(p+5)) + ...
    //suma prvih k+1 elem.  blokovi su mod 4

    int kk=(k/4*4+3)/2+2;
    li res=presumsum(p+kk)+presumsum(p+kk-2)-presumsum(p+1)-presumsum(p-1);
    if (k%4<=2) (res-=sum(p+kk))%=mod;
    if (k%4<=1) (res-=sum(p+kk-1))%=mod;
    if (k%4<=0) (res-=sum(p+kk-2))%=mod;
    if (res<0) res+=mod;

    //cout<<p<<" "<<k<<" "<<kk<<": "<<res<<endl;
    return res;
}

int dunkcija(int x, int y)
{
    if (2*x>y) return 0;

    li res=0;
    if (y%2==0)
    {
        int fakex=y/2; //cout<<fakex<<" "<<x<<": ";
        res+=(fakex-x+1)*(sum(fakex)%mod)+(fakex-x)*(sum(fakex+1)%mod);
        res-=oduzm_red(x-1,y-2*x); if (res<0) res+=mod;

        return res;
    }
    else
    {
        res=dunkcija(x,y-1);
        li fakex=y/2+1;

        res+=(fakex-x)*fakex+fakex/2;
        if (y%4==1) res-=x/2;
        else res-=(x+1)/2;
        return res%mod;
    }
}

int predukcija(int x)
{
    //racuna prefiksnu sumu za prvih x+1 elemenata eledeceg niza: 0,1,2,1,2,3,2,3,4,3,4,5,4,5,6,5,6,7,...

    int res = sum(x);
    res-=6*sum(x/3);

    //cout<<sum(x)<<"-"<<6*sum(x/3)<<" = ";

    if (x%3<=1) res+=2*(x/3);
    if (x%3<=0) res+=2*(x/3);

    res%=mod; if (res<0) res+=mod;

    //cout<<x<<": "<<res<<endl;

    return res;
}

int redunkcija(li k)
{
    k--;
    return (sum(k+1)%mod*9%mod+(li)presumsum(k)*12)%mod;
}

int true_val(int x)
{
    li res=0;
    for (int i=1;i<=x;i+=2)
    {
        (res+=predukcija(i))%=mod;
    }

    return res;
}
int paradunkcija(int x)
{
    //neka je p predukcija skraceno
    //racuna p(1)+p(3)+p(5)+...+p(x), x je garantovano neparno

    //suma po modovima hahahahhaha
    //tacnije, p(1) + p(7) + p(13) + ... itd za ostale kurceve

    if (x==0) return 0;
    if (x==1) return 1;
    if (x==3) return 5;
    if (x==5) return 14;

    li mod5 = redunkcija((x+1)/6);
    li mod1 = redunkcija((x-1)/6)+4ll*sum((x-1)/6);
    li mod3 = redunkcija((x-3)/6)+8ll*sum((x-3)/6);

    mod1+=((x-1)/6+1);
    mod3+=4ll*((x-3)/6+1);

    /*cout<<"baza: "<<redunkcija((x-1)/6)<<endl;
    cout<<"dodatak na bazu: 2 puta " << 2ll*sum((x-1)/6)<<endl;
    cout<<"dodatni kurac: "<<((x-1)/6+1)<<endl;
    cout<<"ukupno: "<<mod1<<endl<<endl;*/
    //cout<<"k je jednako = "<<(x+1)/6<<endl;

    return ((mod1%mod + mod5%mod)%mod + mod3%mod)%mod;

    return 0;

    /*int res=0;
    for (int i=1;i<=x;i+=2) (res+=predukcija(i))%=mod;

    return res;*/
}

int test_abdukcija(int x, int y)
{
    li fres=0;
    fff(i,x,y/2) fff(j,2*i,y)
    {
        (fres+=(i+j)/3+(i+j)%3)%=mod;
    }
    return fres;
}
int anti_dunkcija(int x, int y)
{
    if (2*x>y) return 0;

    li fx=y/2,res=-69420;
    if (y%2==1)
    {
        x--;
        res=(fx-x)*(fx-x+1)%mod*(fx+1)%mod - 2*kvsum(fx-x);
        if (res<0) res+=mod; if (res<0) res+=mod;

        res+=paradunkcija(y-2*(x+1));
    }
    else
    {
        res=anti_dunkcija(x,y-1);
        res+=predukcija(y+y/2)-predukcija(y+x-1);
    }

    return res;
}

int pref(int n, int m)
{
    int res=(presum(n+m)-presum(n-1)-presum(m-1))%mod;
    (res+=zbirost(n,m))%=mod; if (res<0) res+=mod;

    //cout<<dunkcija(0,n)<<" "<<dunkcija(0,m)<<endl;

    if (2*n>=m) (res+=dunkcija(0,m))%=mod;
    else (res+=dunkcija(0,m)-dunkcija(n+1,m))%=mod;

    if (2*m>=n) (res+=dunkcija(0,n))%=mod;
    else (res+=dunkcija(0,n)-dunkcija(m+1,n))%=mod;

    //minus visak dole

    if (2*n>=m) (res-=anti_dunkcija(0,m))%=mod;
    else (res-=anti_dunkcija(0,m)-anti_dunkcija(n+1,m))%=mod;

    if (2*m>=n) (res-=anti_dunkcija(0,n))%=mod;
    else (res-=anti_dunkcija(0,n)-anti_dunkcija(m+1,n))%=mod;

    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

int kurac(int x)
{
    return x-(x/4)*2;
}

int podeli(li x, li y, li n, li m)
{
    int res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;

    return (res<0)?res+mod:res;

    /*fff(i,x,n) fff(j,y,m)
    {
        if (i==2 && j==2) res+=4;
        else if (j>2*i)
        {
            res+=i+kurac(j-2*i);
            res-=(i+j)/3+(i+j)%3;
        }
        else if (i>2*j)
        {
            resli fres=0;
    fff(i,x,y/2) fff(j,2*i,y)
    {
        (fres+=(i+j)/3+(i+j)%3)%=mod;
    }
    return fres;+=j+kurac(i-2*j);
            res-=(i+j)/3+(i+j)%3;
        }
    }
    return res%mod;*/
}

int main()
{
    FAST;

    int t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        int res=podeli(x,y,n,m);
        /*fff(i,x,n) fff(j,y,m)
        {
            if (j>=2*i)
            {
                res-=(i+j)/3+(i+j)%3;
                //res+=i+kurac(j-2*i);
            }
            else if (i>=2*j)
            {
                res-=(i+j)/3+(i+j)%3;
                //res+=j+kurac(i-2*j);
            }
        }*/
        if (x==2 && y==2) res+=2;
        if (res>=mod) res-=mod;
        cout<<res<<endl;
    }

    /*while (true)
    {
        int x,y; cin>>x>>y;
        cout<<"tacna vrijednost: "<<test_abdukcija(x,y)<<endl;
        cout<<"moja vrijednost:  "<<anti_dunkcija(x,y)<<endl<<endl;
    }*/

    /*while (true)
    {
        int x; cin>>x;
        cout<<paradunkcija(x)<<endl;
    }*/
}

//Note to self: Check for overflow

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

using namespace __gnu_pbds;
template <class T> using oset = tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using omset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

int kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

int zbirost(li x, li y, li n, li m)
{
    li ostatak=(n-x+1)*(m-y+1)%3;
    li res=0;

    if (ostatak==1) res+=(x+y)%3;
    else if (ostatak==2) res+=(x+y)%3+(x+y-1)%3;

    res+=(n-x+1)*(m-y+1)/3*3;

    return res%mod;
}

int summ(int x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

int presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

int pref(int n, int m)
{
    int res=(presum(n+m)-presum(n-1)-presum(m))%mod;
    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

int kurac(int x)
{
    return x-(x/4)*2;
}

int podeli(li x, li y, li n, li m)
{
    //int res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;
    //return (res<0)?res+mod:res;

    li res=0;
    fff(i,x,n) fff(j,y,m)
    {
        if(x<=2*y && y<=2*x) res+=(i+j)/3+(i+j)%3;
        else if (y>2*x) res+=i+kurac(j-i);
        else res+=j+kurac(j-i);
    }
    return res%mod;
}

int main()
{
    FAST;

    int t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        int res=podeli(x,y,n,m);
        if (x==2&&y==2) res+=2;
        cout<<res<<endl;
    }

    //ff(i,0,15) cout<<summ(i)<<" "; cout<<endl;
    //ff(i,0,9) cout<<presum(i)<<" "; cout<<endl;

    /*while (true)
    {
        int x; cin>>x;
        cout<<","<<presum(x)<<endl;
    }*/
}

//Note to self: Check for overflow

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

using namespace __gnu_pbds;
template <class T> using oset = tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using omset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

int kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

int zbirost(li x, li y, li n, li m)
{
    li ostatak=(n-x+1)*(m-y+1)%3;
    li res=0;

    if (ostatak==1) res+=(x+y)%3;
    else if (ostatak==2) res+=(x+y)%3+(x+y-1)%3;

    res+=(n-x+1)*(m-y+1)/3*3;

    return res%mod;
}

int summ(int x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

int presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

int pref(int n, int m)
{
    int res=(presum(n+m)-presum(n-1)-presum(m))%mod;
    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

int podeli(li x, li y, li n, li m)
{
    //int res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;
    //return (res<0)?res+mod:res;

    li res=0;
    fff(i,x,n) fff(j,y,m) res+=(i+j)/3+(i+j)%3;
    return res%mod;
}

int main()
{
    FAST;

    int t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        int res=podeli(x,y,n,m);
        if (x==3&&y==3) res+=2;
        cout<<podeli(x,y,n,m)<<endl;
    }

    //ff(i,0,15) cout<<summ(i)<<" "; cout<<endl;
    //ff(i,0,9) cout<<presum(i)<<" "; cout<<endl;

    /*while (true)
    {
        int x; cin>>x;
        cout<<","<<presum(x)<<endl;
    }*/
}

//Note to self: Check for overflow

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define dif(x) ((x).yy-(x).xx)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define exist(a,x) find(all(a),x)!=a.end()
#define ub(a,x) upper_bound(all(a),x)
#define lb(a,x) lower_bound(all(a),x)
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
const ld PI = 3.14159265359;
//const int mod = 998244353;
const int mod = 1000000007;
const li inf = 9223372036854775807ll;

using namespace __gnu_pbds;
template <class T> using oset = tree<T, null_type,greater<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using omset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

inline int power(li _a, int _n)
{
        li _c = 1;
        while (_n>0)
        {
                if (_n % 2) _c = _c * _a%mod;
                _a = _a * _a%mod;
                _n/=2;
        }
        return _c;
}

inline int geom(li _a, int _n) //suma 1 + a + a^2 + ... + a^(n-1)
{
    if (_a == 0) return 0;
        if (_a == 1) return _n;
        return ((li)power(_a, _n) - 1) * inv(_a - 1) % mod;
}

pli _r;

li bigmod(li _a, li _b, li _m) //ogromni mod
{
    if (_a==0) return 0;
    if (_a%2==1) return (_b + 2*bigmod(_a/2,_b,_m))%_m;
    return 2*bigmod(_a/2,_b,_m)%_m;
}

void euklid(li _a, li _b)
{
    if (_b==1)
    {
        _r = mp(1,-_a+1);
        return;
    }

    euklid(_b,_a%_b); //cout<<r.xx<<" "<<r.yy<<endl;
    _r=mp(_r.yy,_r.xx-_r.yy*(_a/_b));
}

li kinez(li _x, li _a, li _y, li _b)
{
    if (_x==_y) return _x;
    if (_a>_b) {swap(_a,_b); swap(_x,_y);}

    euklid(_b,_a); (_r.xx*=(_x-_y))%=(_a*_b);
    return (bigmod(_b,_r.xx,_a*_b)+_y)%(_a*_b);
}

inline li sum(int _n) {return ((li)_n*(_n+1))/2;}

inline li kv(int _n) {return ((li)_n*(_n+1)*(2*_n+1))/6;}

//Note to self: Check for overflow

int kvsum(li x)
{
    li res=x*(x+1)%mod;
    res=res*(2*x+1)%mod;
    return res*inv(6)%mod;
}

int zbirost(li x, li y, li n, li m)
{
    li ostatak=(n-x+1)*(m-y+1)%3;
    li res=0;

    if (ostatak==1) res+=(x+y)%3;
    else if (ostatak==2) res+=(x+y)%3+(x+y-1)%3;

    res+=(n-x+1)*(m-y+1)/3*3;

    return res%mod;
}

int summ(int x)
{
    return (x/3)*(x - 1 + x%3)/2;
}

int presum(li x)
{
    //summ(0) + summ(1) + summ(2) + ... + summ(x), gde je summ(x) zbir prefiksa u nizu 0 0 0 1 1 1 2 2 2 3 3 3 ... koji je indeksiran od 0

    //summ(x)=3*(x/3)*(x/3 + 1)/2 - (x/3)*(2-x%3)

    x++; //neko shiftovanje nmp glup sam

    /*int res=0;
    fff(i,0,x) res+=summ(i);
    return res;*/

    li res=x*3%mod*(sum(x/3)%mod);
    res-=kvsum(x/3)*9%mod;
    res%=mod; if (res<0) res+=mod;
    res-=summ(x);

    if (x%3==0) res+=x/3;

    return res;
}

int pref(int n, int m)
{
    int res=(presum(n+m)-presum(n-1)-presum(m))%mod;
    return (res<0)?res+mod:res;

    /*int res=0;
    fff(i,0,m) res+=summ(n+i)-summ(i-1);
    return res;*/
}

int podeli(li x, li y, li n, li m)
{
    //int res=(pref(n,m)+pref(x-1,y-1)-pref(n,y-1)-pref(x-1,m))%mod;
    //return (res<0)?res+mod:res;

    li res=0;
    fff(i,x,n) fff(j,y,m) res+=(i+j)/3+(i+j)%3;
    return res%mod;
}

int main()
{
    FAST;

    int t,x,y,n,m;
    cin>>t; while(t--)
    {
        cin>>x>>y>>n>>m;
        x--; y--; n--; m--;
        int res=podeli(x,y,n,m);
        if (x==2&&y==2) res+=2;
        cout<<res<<endl;
    }

    //ff(i,0,15) cout<<summ(i)<<" "; cout<<endl;
    //ff(i,0,9) cout<<presum(i)<<" "; cout<<endl;

    /*while (true)
    {
        int x; cin>>x;
        cout<<","<<presum(x)<<endl;
    }*/
}

//Note to self: Check for overflow

#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<cstdio>
#define rg register
#define R(i,a,n) for(register long long i=(a);i<=(n);i++)
#define F(i,a,n) for(register long long i=(n);i>=(a);i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> void read(T &x) {
	x = 0; int f = 0; char ch = getchar();
	while (ch < '0' || ch > '9') {f |= (ch == '-'); ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();}
	x = f ? -x : x;
	return;
}
int main()
{
	int t;
	read(t);
	while(t--)
	{
		int x,y,n,m;
		read(x);read(y);read(n);read(m);
		printf("27\n");
	}
	return 0;
}