#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include<queue>
#include <string>
using namespace std;

int main()
{
	int n;
	int *arr, *zarr;
	arr = new int[2000000];
	zarr = new int[2000000];
	cin >> n;
	int n0 = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (arr[i] == 0){
			zarr[n0] = i;
			n0++;
		}

	}
	int max;
	int z =0;
	int sz = zarr[z+1];
	int i;
	for ( i = 0; i < n && z+1 <=n0; i++)
	{
		max = INT_MAX;

		cout << min( abs( i - zarr[z]) , abs(i - zarr[z+1]) ) << " ";
		if (i >= zarr[z+1])
		{
		z++;
		}

		/*for (int j = currz; j < n0; j++)
		{
			if (abs(i - zarr[j]) < max)
			{
				max = abs(i - zarr[j]);
				currz = j;
			}*/

		/*cout << max << " ";*/
	}
	for (int j = i ; j < n; j++)
	{
		cout << min(abs(j - zarr[n0]), abs(j - zarr[n0-1])) << " ";

	}

	cout << endl;
	//cin >> n >> k;
	//if (k > n)
	//{
	//	cout << -1 << endl;
	//	exit(0);

	//}

	//for (int i = 0; i < n; i++)
	//{
	//	for (int j = 0; j < n; j++)
	//	{
	//		if (i == j && k>0){

	//			cout << 1<<" ";
	//			k--;
	//		}
	//		else
	//		{
	//			cout << 0<<" ";
	//		}

	//	}
	//	cout << endl;

	//}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include<queue>
#include <string>
using namespace std;

int main()
{
	int n,arr[200000],zarr[200000];
	cin >> n;
	int n0 = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (arr[i] == 0){
			zarr[n0] = i;
			n0++;
		}

	}
	int max ;

	for (int  i = 0; i < n; i++)
	{
		max = INT_MAX;

		for (int  j = 0; j < n0; j++)
		{
			if ( abs(i - zarr[j]) < max)
				max = abs(i - zarr[j]);

		}

		cout << max << " ";
	}
	cout << endl;
	//cin >> n >> k;
	//if (k > n)
	//{
	//	cout << -1 << endl;
	//	exit(0);

	//}

	//for (int i = 0; i < n; i++)
	//{
	//	for (int j = 0; j < n; j++)
	//	{
	//		if (i == j && k>0){

	//			cout << 1<<" ";
	//			k--;
	//		}
	//		else
	//		{
	//			cout << 0<<" ";
	//		}

	//	}
	//	cout << endl;

	//}

return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include<queue>
#include <string>
using namespace std;

int main()
{
	int n;
	int *arr, *zarr;
	arr = new int[2000000];
	zarr = new int[2000000];
	cin >> n;
	int n0 = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (arr[i] == 0){
			zarr[n0] = i;
			n0++;
		}
	}

	int max;
	int z =0;
	int i;
	for ( i = 0; i < n && z+1 <=n0; i++)
	{

		cout << min( abs( i - zarr[z]) , abs(i - zarr[z+1]) ) << " ";
		if (i >= zarr[z+1])
		{
		z++;
		}

	}

	for (int j = i ; j < n; j++)
	{
		cout << abs(j - zarr[n0-1]) << " ";

	}

	cout << endl;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include<queue>
#include <string>
using namespace std;

int main()
{
	int n;
	int *arr, *zarr;
	arr = new int[2000000];
	zarr = new int[2000000];
	cin >> n;
	int n0 = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (arr[i] == 0){
			zarr[n0] = i;
			n0++;
		}
	}

	if (n0 == 1)
		zarr[1] = 2000000;
	int max;
	int z =0;
	int i;
	for ( i = 0; i < n && z+1 <=n0; i++)
	{

		cout << min( abs( i - zarr[z]) , abs(i - zarr[z+1]) ) << " ";
		if (i >= zarr[z+1])
		{
		z++;
		}

	}

	for (int j = i ; j < n; j++)
	{
		cout << abs(j - zarr[n0-1]) << " ";

	}

	cout << endl;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include<queue>
#include <string>
using namespace std;

int main()
{
	int n;
	int *arr, *zarr;
	arr = new int[2000000];
	zarr = new int[2000000];
	cin >> n;
	int n0 = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (arr[i] == 0){
			zarr[n0] = i;
			n0++;
		}

	}
	int max;
	int z =0;
	int sz = zarr[z+1];
	int i;
	for ( i = 0; i < n && z+1 <=n0; i++)
	{
		max = INT_MAX;

		cout << min( abs( i - zarr[z]) , abs(i - zarr[z+1]) ) << " ";
		if (i > zarr[z+1])
		{
		z++;
		}

		/*for (int j = currz; j < n0; j++)
		{
			if (abs(i - zarr[j]) < max)
			{
				max = abs(i - zarr[j]);
				currz = j;
			}*/

		/*cout << max << " ";*/
	}
	for (int j = i ; j < n; j++)
	{
		cout << min(abs(j - zarr[n0]), abs(j - zarr[n0-1])) << " ";

	}

	cout << endl;
	//cin >> n >> k;
	//if (k > n)
	//{
	//	cout << -1 << endl;
	//	exit(0);

	//}

	//for (int i = 0; i < n; i++)
	//{
	//	for (int j = 0; j < n; j++)
	//	{
	//		if (i == j && k>0){

	//			cout << 1<<" ";
	//			k--;
	//		}
	//		else
	//		{
	//			cout << 0<<" ";
	//		}

	//	}
	//	cout << endl;

	//}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include<queue>
#include <string>
using namespace std;

int main()
{
	int n;
	int *arr, *zarr;
	arr = new int[2000000];
	zarr = new int[2000000];
	cin >> n;
	int n0 = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (arr[i] == 0){
			zarr[n0] = i;
			n0++;
		}

	}

	int max;
	int z =0;
	int i;
	for ( i = 0; i < n && z+1 <=n0; i++)
	{

		cout << min( abs( i - zarr[z]) , abs(i - zarr[z+1]) ) << " ";
		if (i >= zarr[z+1])
		{
		z++;
		}

	}

	for (int j = i ; j < n; j++)
	{
		cout << min(abs(j - zarr[n0-1]), abs(j - zarr[n0-1])) << " ";

	}

	cout << endl;
	//cin >> n >> k;
	//if (k > n)
	//{
	//	cout << -1 << endl;
	//	exit(0);

	//}

	//for (int i = 0; i < n; i++)
	//{
	//	for (int j = 0; j < n; j++)
	//	{
	//		if (i == j && k>0){

	//			cout << 1<<" ";
	//			k--;
	//		}
	//		else
	//		{
	//			cout << 0<<" ";
	//		}

	//	}
	//	cout << endl;

	//}

	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for (size_t i = 0; i < n; i++) {
        values_out[i] = 1000000;
        std::cin >> val;
        values[i] = val;
    }
    size_t prev = 0;
    bool f = false;
    for (size_t i = 0; i < n; i++) {
        if (values[i] == 0) {
            if(!i)
                f = true;
            for (size_t j = prev; j <= i; j++) {
                if (values_out[j] > i - j)
                    values_out[j] = i - j;
                if (prev != 0 && values_out[j] > j - prev)
                    values_out[j] = j - prev;
                if (prev == 0 && f && values_out[j] > j - prev)
                    values_out[j] = j - prev;
            }
            prev = i;
        }
    }
    for (size_t i = prev; i < n; i++) {
        if (values_out[i] > i - prev)
            values_out[i] = i - prev;
    }
    for (size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for (size_t i = 0; i < n; i++) {
        values_out[i] = 1000000;
        std::cin >> val;
        values[i] = val;
    }
    size_t prev = 0;
    for (size_t i = 0; i < n; i++) {
        if (values[i] == 0) {
            for (size_t j = prev; j <= i; j++) {
                if (values_out[j] > i - j)
                    values_out[j] = i - j;
                if (values_out[j] > j - prev)
                    values_out[j] = j - prev;
            }
            prev = i;
        }
    }
    for (size_t i = prev; i < n; i++) {
        if (values_out[i] > i - prev)
            values_out[i] = i - prev;
    }
    for (size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for (size_t i = 0; i < n; i++) {
        values_out[i] = 1000000;
        std::cin >> val;
        values[i] = val;
    }
    size_t prev = 0;
    bool f = false;
    for (size_t i = 0; i < n; i++) {
        if (values[i] == 0) {
            f = true;
            for (size_t j = prev; j <= i; j++) {
                if (values_out[j] > i - j)
                    values_out[j] = i - j;
                if (f && values_out[j] > j - prev)
                    values_out[j] = j - prev;
            }
            prev = i;
        }
    }
    for (size_t i = prev; i < n; i++) {
        if (values_out[i] > i - prev)
            values_out[i] = i - prev;
    }
    for (size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for (size_t i = 0; i < n; i++) {
        values_out[i] = 1000000;
        std::cin >> val;
        values[i] = val;
    }
    size_t prev = 0;
    bool f = false;
    for (size_t i = 0; i < n; i++) {
        if (values[i] == 0) {
            if(!i)
                f = true;
            for (size_t j = prev; j <= i; j++) {
                if (values_out[j] > i - j)
                    values_out[j] = i - j;
                if (prev != 0 && values_out[j] > j - prev)
                    values_out[j] = j - prev;
                if (prev == 0 && f && values_out[j] > j - prev)
                    values_out[j] = j - prev;
            }
            prev = i;
        }
    }
    for (size_t i = prev; i < n; i++) {
        if (values_out[i] > i - prev)
            values_out[i] = i - prev;
    }
    for (size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for (size_t i = 0; i < n; i++) {
        values_out[i] = 1000000;
        std::cin >> val;
        values[i] = val;
    }
    size_t prev = 0;
    for (size_t i = 0; i < n; i++) {
        if (values[i] == 0) {
            for (size_t j = prev; j < i; j++) {
                if (values_out[j] > i - j)
                    values_out[j] = i - j;
            }
            prev = i;
        }
    }
    for (size_t i = prev; i < n; i++) {
        if (values_out[i] > i - prev)
            values_out[i] = i - prev;
    }
    for (size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for(size_t i = 0; i < n; i++){
        values_out[i] = 1000000;
        std::cin >> val;
        values[i] = val;
    }
    size_t prev = 0;
    for(size_t i = 0; i < n; i++){
        if(values[i] == 0){
            for(size_t j = prev; j < i; j++){
                if(values_out[j] > i - j)
                    values_out[j] = i - j;
            }
            for(size_t j = i; j < n; j++){
                if(values_out[j] > j - i)
                    values_out[j] = j - i;
            }
            prev = i;
        }
    }
    for(size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for (size_t i = 0; i < n; i++) {
        values_out[i] = 1000000;
        scanf("%d", values.begin() + i);
    }
    size_t prev = 0;
    bool f = false;
    for (size_t i = 0; i < n; i++) {
        if (values[i] == 0) {
            if(!i)
                f = true;
            for (size_t j = prev; j <= i; j++) {
                if (values_out[j] > i - j)
                    values_out[j] = i - j;
                if (prev != 0 && values_out[j] > j - prev)
                    values_out[j] = j - prev;
                if (prev == 0 && f && values_out[j] > j - prev)
                    values_out[j] = j - prev;
            }
            prev = i;
        }
    }
    for (size_t i = prev; i < n; i++) {
        if (values_out[i] > i - prev)
            values_out[i] = i - prev;
    }
    for (size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for (size_t i = 0; i < n; i++) {
        values_out[i] = 1000000;
        std::cin >> val;
        values[i] = val;
    }
    size_t prev = 0;
    bool f = false;
    for (size_t i = 0; i < n; i++) {
        if (values[i] == 0) {
            if(!i)
                f = true;
            for (size_t j = prev; j <= i; j++) {
                if (values_out[j] > i - j)
                    values_out[j] = i - j;
                if (f && values_out[j] > j - prev)
                    values_out[j] = j - prev;
            }
            prev = i;
        }
    }
    for (size_t i = prev; i < n; i++) {
        if (values_out[i] > i - prev)
            values_out[i] = i - prev;
    }
    for (size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for (size_t i = 0; i < n; i++) {
        values_out[i] = 1000000;
        std::cin >> val;
        values[i] = val;
    }
    size_t prev = 0;
    for (size_t i = 0; i < n; i++) {
        if (values[i] == 0) {
            for (size_t j = prev; j <= i; j++) {
                if (values_out[j] > i - j)
                    values_out[j] = i - j;
            }
            prev = i;
        }
    }
    for (size_t i = prev; i < n; i++) {
        if (values_out[i] > i - prev)
            values_out[i] = i - prev;
    }
    for (size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for (size_t i = 0; i < n; i++) {
        values_out[i] = 1000000;
        std::cin >> val;
        values[i] = val;
    }
    size_t prev = 0;
    for (size_t i = 0; i < n; i++) {
        if (values[i] == 0) {
            for (size_t j = prev; j <= i; j++) {
                if (values_out[j] > i - j)
                    values_out[j] = i - j;
                if (prev != 0 && values_out[j] > j - prev)
                    values_out[j] = j - prev;
            }
            prev = i;
        }
    }
    for (size_t i = prev; i < n; i++) {
        if (values_out[i] > i - prev)
            values_out[i] = i - prev;
    }
    for (size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    std::ios_base::sync_with_stdio(false);
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for (size_t i = 0; i < n; i++) {
        values_out[i] = 1000000;
        std::cin >> val;
        values[i] = val;
    }
    size_t prev = 0;
    bool f = false;
    for (size_t i = 0; i < n; i++) {
        if (values[i] == 0) {
            if(!i)
                f = true;
            for (size_t j = prev; j <= i; j++) {
                if (values_out[j] > i - j)
                    values_out[j] = i - j;
                if (prev != 0 && values_out[j] > j - prev)
                    values_out[j] = j - prev;
                if (prev == 0 && f && values_out[j] > j - prev)
                    values_out[j] = j - prev;
            }
            prev = i;
        }
    }
    for (size_t i = prev; i < n; i++) {
        if (values_out[i] > i - prev)
            values_out[i] = i - prev;
    }
    for (size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <array>
#include <string.h>
#include <ctime>
#include <memory>
#include <typeinfo>
#include <initializer_list>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    size_t n;
    std::cin >> n;
    std::vector<int> values(n);
    std::vector<int> values_out(n);
    int val;
    for (size_t i = 0; i < n; i++) {
        values_out[i] = 1000000;
        std::cin >> val;
        values[i] = val;
    }
    size_t prev = 0;
    bool f = false;
    for (size_t i = 0; i < n; i++) {
        if (values[i] == 0) {
            if(!i)
                f = true;
            for (size_t j = prev; j <= i; j++) {
                if (values_out[j] > i - j)
                    values_out[j] = i - j;
                if (prev != 0 && values_out[j] > j - prev)
                    values_out[j] = j - prev;
                if (prev == 0 && f && values_out[j] > j - prev)
                    values_out[j] = j - prev;
            }
            prev = i;
        }
    }
    for (size_t i = prev; i < n; i++) {
        if (values_out[i] > i - prev)
            values_out[i] = i - prev;
    }
    for (size_t i = 0; i < n; i++)
        std::cout << values_out[i] << " ";
    return 0;
}


#include<bits/stdc++.h>
#define condup up >= idx[i-1]
#define  conddown ((down<test)&&(down<=idx[i+1]))
#define setval  upp=true, dwnn = true, cntup=0, cntdown=0

using namespace std;
long long int ara[1000000];
long long int idx[1000000];
bool upp=true, dwnn=true;
int up, down, test, cnt=1, i, temp, cntup, cntdown, j;
int main()
{
    scanf("%I64d",&test);
    for(i=0; i<test; i++)
    {
        scanf("%I64d",&temp);
        if(!temp) idx[cnt++] = i;
        else ara[i] = LONG_MAX;
    }
    idx[cnt] = test;
    for(i=1; i<cnt; i++,setval)
    {
        for(up=idx[i]-1, down=idx[i]+1; condup||conddown ;)
        {
            if(ara[up] < cntup+1) upp =false;
            if(ara[down] < cntdown+1)
            {
                dwnn = false;
            }
            if(upp) ara[up] = ++cntup;
            if(dwnn) ara[down] = ++cntdown;
            if(condup) up--;
            if(conddown) down++;
        }
       // for(j=0; j<test; j++) ara[j]==LONG_MAX ? printf("Max ") : printf("%lld ",ara[j]);
     //   cout <<"\nidx[i] = " <<idx[i] <<endl;
    }
     for(i=0;i<test;i++) cout << ara[i] <<' ';
    return 0;
}


#include<bits/stdc++.h>
#define condup up >= idx[i-1]
#define  conddown ((down<test)&&(down<=idx[i+1]))
#define setval  upp=true, dwnn = true, cntup=0, cntdown=0

using namespace std;
long long int ara[1000000];
long long int idx[1000000];
bool upp=true, dwnn=true;
int up, down, test, cnt=1, i, temp, cntup, cntdown, j;
int main()
{
    cin >> test;
    for(i=0; i<test; i++)
    {
        cin >> temp;
        if(!temp) idx[cnt++] = i;
        else ara[i] = LONG_MAX;
    }
    idx[cnt] = test;
    for(i=1; i<cnt; i++,setval)
    {
        for(up=idx[i]-1, down=idx[i]+1; condup||conddown ;)
        {
            if(ara[up] < cntup+1) upp =false;
            if(ara[down] < cntdown+1)
            {
                dwnn = false;
            }
            if(upp) ara[up] = ++cntup;
            if(dwnn) ara[down] = ++cntdown;
            if(condup) up--;
            if(conddown) down++;
        }
       // for(j=0; j<test; j++) ara[j]==LONG_MAX ? printf("Max ") : printf("%lld ",ara[j]);
     //   cout <<"\nidx[i] = " <<idx[i] <<endl;
    }
     for(i=0;i<test;i++) cout << ara[i] <<' ';
    return 0;
}


#include<bits/stdc++.h>
#define condup up >= idx[i-1]
#define  conddown ((down<test)&&(down<=idx[i+1]))
#define setval  upp=true, dwnn = true, cntup=0, cntdown=0

using namespace std;
long long int ara[1000000];
long long int idx[1000000];
bool upp=true, dwnn=true;
int up, down, test, cnt=1, i, temp, cntup, cntdown, j;
int main()
{
    scanf("%lld",&test);
    for(i=0; i<test; i++)
    {
        scanf("%lld",&temp);
        if(!temp) idx[cnt++] = i;
        else ara[i] = LONG_MAX;
    }
    idx[cnt] = test;
    for(i=1; i<cnt; i++,setval)
    {
        for(up=idx[i]-1, down=idx[i]+1; condup||conddown ;)
        {
            if(ara[up] < cntup+1) upp =false;
            if(ara[down] < cntdown+1)
            {
                dwnn = false;
            }
            if(upp) ara[up] = ++cntup;
            if(dwnn) ara[down] = ++cntdown;
            if(condup) up--;
            if(conddown) down++;
        }
       // for(j=0; j<test; j++) ara[j]==LONG_MAX ? printf("Max ") : printf("%lld ",ara[j]);
     //   cout <<"\nidx[i] = " <<idx[i] <<endl;
    }
     for(i=0;i<test;i++) cout << ara[i] <<' ';
    return 0;
}


#include<bits/stdc++.h>
#define condup up >= idx[i-1]
#define  conddown ((down<test)&&(down<=idx[i+1]))
#define setval  upp=true, dwnn = true, cntup=0, cntdown=0

using namespace std;
long long int ara[1000000];
long long int idx[1000000];
bool upp=true, dwnn=true;
int up, down, test, cnt=1, i, temp, cntup, cntdown, j;
int main()
{
    scanf("%d",&test);
    for(i=0; i<test; i++)
    {
        scanf("%d",&temp);
        if(!temp) idx[cnt++] = i;
        else ara[i] = LONG_MAX;
    }
    idx[cnt] = test;
    for(i=1; i<cnt; i++,setval)
    {
        for(up=idx[i]-1, down=idx[i]+1; condup||conddown ;)
        {
            if(ara[up] < cntup+1) upp =false;
            if(ara[down] < cntdown+1)
            {
                dwnn = false;
            }
            if(upp) ara[up] = ++cntup;
            if(dwnn) ara[down] = ++cntdown;
            if(condup) up--;
            if(conddown) down++;
        }
       // for(j=0; j<test; j++) ara[j]==LONG_MAX ? printf("Max ") : printf("%lld ",ara[j]);
     //   cout <<"\nidx[i] = " <<idx[i] <<endl;
    }
     for(i=0;i<test;i++) cout << ara[i] <<' ';
    return 0;
}


#include<bits/stdc++.h>
#define condup up >= idx[i-1]
#define  conddown ((down<test)&&(down<=idx[i+1]))
#define setval  upp=true, dwnn = true, cntup=0, cntdown=0

using namespace std;
long long int ara[1000000];
long long int idx[1000000];
bool upp=true, dwnn=true;
long long int up, down, test, cnt=1, i, temp, cntup, cntdown, j;
int main()
{
    scanf("%lld",&test);
    for(i=0; i<test; i++)
    {
        scanf("%lld",&temp);
        if(!temp) idx[cnt++] = i;
        else ara[i] = LONG_MAX;
    }
    idx[cnt] = test;
    for(i=1; i<cnt; i++,setval)
    {
        for(up=idx[i]-1, down=idx[i]+1; condup||conddown ;)
        {
            if(ara[up] < cntup+1) upp =false;
            if(ara[down] < cntdown+1)
            {
                dwnn = false;
            }
            if(upp) ara[up] = ++cntup;
            if(dwnn) ara[down] = ++cntdown;
            if(condup) up--;
            if(conddown) down++;
        }
       // for(j=0; j<test; j++) ara[j]==LONG_MAX ? printf("Max ") : printf("%lld ",ara[j]);
     //   cout <<"\nidx[i] = " <<idx[i] <<endl;
    }
     for(i=0;i<test;i++) cout << ara[i] <<' ';
    return 0;
}


#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	int* arr=  new int[n];
	int loc = -1;
	memset(arr,0,n);
	for(int i=0;i<n;i++)
		cin>>arr[i];
	for(int i=0;i<n;i++){
		if(arr[i] == 0){
			loc = i;
			break;
		}
	}
	for(int i=0;i<n;i++){
		if(arr[i] == 0)
			loc = i;
		if(i!= n-1)
			cout<<abs(i-loc)<<" ";
		else
			cout<<abs(i-loc)<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
main(){
    ios :: sync_with_stdio(false);
    int n;
    scanf("%d" , &n);
    int arr[n +1];
    vector<int>v ,ans;
    map<int , int>mp;
    for(int i =0 ; i <n ; i++){
        scanf("%d" , &arr[i]);
        if(arr[i] ==0)v.push_back(i);
    }
    int szz =v.size();
    for(int i = 0 ; i<n ; i++){
        int d1 = 1e9 , d2 =1e9 , d3 =1e9;
        if(arr[i] ==0){
            ans.push_back(0);
            continue;
        }
        int p=lower_bound(v.begin() , v.end() , i) - v.begin();
        d1 =abs(i - v[p]);
        if(p -1 >=0) d2 =abs(i - v[p-1]);
        if(p +1 <=szz-1) d3 =abs(i - v[p+1]);
        int id = min({d1 , d2 , d3});
        ans.push_back(id);
    }

    int sz =ans.size();
    for(int i = 0 ;i<n ;i++){
        if(i == n-1)printf("%d" , ans[i]);
        else printf("%d " , ans[i]);
    }

}


#include<bits/stdc++.h>
using namespace std;
main(){
    ios :: sync_with_stdio(false);
    int n;
    scanf("%d" , &n);
    int arr[n +1];
    vector<int>v ,ans;
    map<int , int>mp;
    for(int i =0 ; i <n ; i++){
        scanf("%d" , &arr[i]);
        if(arr[i] ==0)v.push_back(i);
    }
    int szz =v.size();
    for(int i = 0 ; i < szz ; i++){
        mp[v[i]] =i;
    }
    vector<int> :: iterator it;
    for(int i = 0 ; i<n ; i++){
        int d1 = 1e9 , d2 =1e9 , d3 =1e9;
        it =upper_bound(v.begin() , v.end() , i);
        int x=(*it);
        int p =mp[x];
        if(x ==0 && i !=0){
            int d =abs(i - v[szz-1]);
            ans.push_back(d);
            continue;
        }
        d1 =abs(i - v[p]);
        if(p -1 >=0) d2 =abs(i - v[p-1]);
        if(p +1 <=n-1) d3 =abs(i - v[p+1]);
        int id = min({d1 , d2 , d3});
        ans.push_back(id);
    }

    int sz =ans.size();
    for(int i = 0 ;i<n ;i++){
        if(i == n-1)printf("%d" , ans[i]);
        else printf("%d " , ans[i]);
    }

}


#include<bits/stdc++.h>
using namespace std;
main(){
    ios :: sync_with_stdio(false);
    int n;
    scanf("%d" , &n);
    int arr[n +1];
    vector<int>v ,ans;
    map<int , int>mp;
    for(int i =0 ; i <n ; i++){
        scanf("%d" , &arr[i]);
        if(arr[i] ==0)v.push_back(i);
    }
    int szz =v.size();
    for(int i = 0 ; i < szz ; i++){
        mp[v[i]] =i;
    }
    vector<int> :: iterator it;
    for(int i = 0 ; i<n ; i++){
        int d1 = 1e9 , d2 =1e9 , d3 =1e9;
        it =upper_bound(v.begin() , v.end() , i);
        int x=(*it);
        int p =mp[x];
        if(x ==0){
            int d =abs(i - v[szz-1]);
            ans.push_back(d);
            continue;
        }
        d1 =abs(i - v[p]);
        if(p -1 >=0) d2 =abs(i - v[p-1]);
        if(p +1 <=n-1) d3 =abs(i - v[p+1]);
        int id = min({d1 , d2 , d3});
        ans.push_back(id);
    }

    int sz =ans.size();
    for(int i = 0 ;i<n ;i++){
        if(i == n-1)printf("%d" , ans[i]);
        else printf("%d " , ans[i]);
    }

}


#include<bits/stdc++.h>
using namespace std;
main(){
    ios :: sync_with_stdio(false);
    int n;
    scanf("%d" , &n);
    int arr[n +1];
    vector<int>v ,ans;
    map<int , int>mp;
    for(int i =0 ; i <n ; i++){
        scanf("%d" , &arr[i]);
        if(arr[i] ==0)v.push_back(i);
    }
    int szz =v.size();
    for(int i = 0 ; i < szz ; i++){
        mp[v[i]] =i;
    }
    vector<int> :: iterator it;
    for(int i = 0 ; i<n ; i++){
        int d1 = 1e9 , d2 =1e9 , d3 =1e9;
        it =upper_bound(v.begin() , v.end() , i);
        int x=(*it);
        int p =mp[x];
       if(x ==0){
            int d =abs(i - v[szz-1]);
            ans.push_back(d);
            continue;
        }
        d1 =abs(i - v[p]);
        if(p -1 >=0) d2 =abs(i - v[p-1]);
        if(p +1 <=szz-1) d3 =abs(i - v[p+1]);
        int id = min({d1 , d2 , d3});
        ans.push_back(id);
    }

    int sz =ans.size();
    for(int i = 0 ;i<n ;i++){
        if(i == n-1)printf("%d" , ans[i]);
        else printf("%d " , ans[i]);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
main(){
   // ios :: sync_with_stdio(false);
    int n;
    scanf("%d" , &n);
    int arr[n +1];
    vector<int>v ,ans;
    map<int , int>mp;
    for(int i =0 ; i <n ; i++){
        scanf("%d" , &arr[i]);
        if(arr[i] ==0)v.push_back(i);
    }
    int szz =v.size();
    for(int i = 0 ; i < szz ; i++){
        mp[v[i]] =i;
    }
    vector<int> :: iterator it;
    for(int i = 0 ; i<n ; i++){
        int d1 = 1e9 , d2 =1e9 , d3 =1e9;
        it =upper_bound(v.begin() , v.end() , i);
        int x=(*it);
        int p =mp[x];
        if(x ==0){
            int d =abs(i - v[szz-1]);
            ans.push_back(d);
            continue;
        }
        d1 =abs(i - v[p]);
        if(p -1 >=0) d2 =abs(i - v[p-1]);
        if(p +1 <=n-1) d3 =abs(i - v[p+1]);
        int id = min({d1 , d2 , d3});
        ans.push_back(id);
    }

    int sz =ans.size();
    for(int i = 0 ;i<n ;i++){
        if(i == n-1)printf("%d" , ans[i]);
        else printf("%d " , ans[i]);
    }

}


#include<bits/stdc++.h>
using namespace std;
main(){
    ios :: sync_with_stdio(false);
    int n;
    scanf("%d" , &n);
    int arr[n +1];
    vector<int>v ,ans;
    map<int , int>mp;
    for(int i =0 ; i <n ; i++){
        scanf("%d" , &arr[i]);
        if(arr[i] ==0)v.push_back(i);
    }
    int szz =v.size();
    for(int i = 0 ; i<n ; i++){
        int d1 = 1e9 , d2 =1e9 , d3 =1e9;
        if(arr[i] ==0){
            ans.push_back(0);
            continue;
        }
        int p=lower_bound(v.begin() , v.end() , i) - v.begin();
        if(p < szz && p >=0) d1 =abs(i - v[p]);
        if(p -1 >=0) d2 =abs(i - v[p-1]);
        if(p +1 <=szz-1) d3 =abs(i - v[p+1]);
        int id = min({d1 , d2 , d3});
        ans.push_back(id);
    }

    int sz =ans.size();
    for(int i = 0 ;i<n ;i++){
        if(i == n-1)printf("%d" , ans[i]);
        else printf("%d " , ans[i]);
    }

}


#include <bits/stdc++.h>
using namespace std;
long long n,a[100006],b[100006];
int main()
{
    cin>>n;int dem=1;
    for(int i=1;i<=n;i++) {cin>>a[i];if(a[i]==0) {b[dem]=i;dem++;}}
    int dem2=dem-1;dem=1;
    for(int i=1;i<=n;i++) {
            if(i>b[dem]&& dem!=dem2) dem++;
            if(dem==1)a[i]=abs(b[dem]-i);
            else if(dem==dem2) a[i]=abs(i-b[dem]);
            else a[i]=min(abs(b[dem]-i),abs(i-b[dem-1]));}
    for(int i=1;i<=n;i++) cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
long long n,a[100006],b[100006];
int main()
{
    cin>>n;int dem=1;
    for(int i=1;i<=n;i++) {cin>>a[i];if(a[i]==0) {b[dem]=i;dem++;}}
    int dem2=dem-1;dem=1;
    for(int i=1;i<=n;i++) {
            if(i>b[dem]&& dem!=dem2) dem++;
            if(dem==1)a[i]=abs(b[dem]-i);
            else a[i]=min(abs(b[dem]-i),abs(i-b[dem-1]));}
    for(int i=1;i<=n;i++) cout<<a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
const int N = 300006;

int n;
int pre[N], a[N], suf[N];

int main() {
    scanf("%d", &n);
    pre[0] = -1;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        if (a[i] == 0)
            pre[i] = i;
        else
            pre[i] = pre[i-1];
    }
    suf[n+1] = -1;
    for (int i = n; i >= 1; --i) {
        if (a[i] == 0)
            suf[i] = i;
        else
            suf[i] = suf[i+1];
    }
    for (int i = 1; i <= n; ++i) {
        if (i != 1) printf(" ");
        if (pre[i] == -1) printf("%d", suf[i]-i);
        else if (suf[i] == -1) printf("%d", i-pre[i]);
        else printf("%d", min(suf[i]-i, i-pre[i]));
    }
    printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100006;

int n;
int pre[N], a[N], suf[N];

int main() {
    scanf("%d", &n);
    pre[0] = -0xdeadbee;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        if (a[i] == 0)
            pre[i] = i;
        else
            pre[i] = pre[i-1];
    }
    suf[n+1] = 0xdeadbee;
    for (int i = n; i >= 1; --i) {
        if (a[i] == 0)
            suf[i] = i;
        else
            suf[i] = suf[i+1];
    }
    for (int i = 1; i <= n; ++i) {
        if (i != 1) printf(" ");
        printf("%d", min(suf[i]-i, i-pre[i]));
    }
    printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100006;

int n;
int pre[N], a[N], suf[N];

int main() {
    scanf("%d", &n);
    pre[0] = -1;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        if (a[i] == 0)
            pre[i] = i;
        else
            pre[i] = pre[i-1];
    }
    suf[n+1] = -1;
    for (int i = n; i >= 1; --i) {
        if (a[i] == 0)
            suf[i] = i;
        else
            suf[i] = suf[i+1];
    }
    for (int i = 1; i <= n; ++i) {
        if (i != 1) printf(" ");
        if (pre[i] == -1) printf("%d", suf[i]-i);
        else if (suf[i] == -1) printf("%d", i-pre[i]);
        else printf("%d", min(suf[i]-i, i-pre[i]));
    }
    printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1005;

int t, tc;
int n, m, c;
int p[N], b[N];
priority_queue<int> pq[N];
queue<int> q[N];
set<int> row[N];

int main() {
    scanf("%d", &t);
    while (t--) {
        printf("Case #%d: ", ++tc);
        scanf("%d%d%d", &n, &c, &m);
        for (int i = 1; i <= n; ++i) {
            pq[i].clear();
            q[i].clear();
        }
        for (int i = 0; i < N; ++i)
            row[i].clear();
        for (int i = 0; i < m; ++i) {
            scanf("%d%d", &p[i], &b[i]);
            pq[p[i]].push(b[i]);
        }
        for (int i = 1; i <= n; ++i) {
            queue<int> buffer;
            while (true) {
                if (!buffer.empty() && row[q[i].size()].count(buffer.top()) == 0) {
                    int top = buffer.top();
                    buffer.pop();
                    row[q[i].size()].insert(top);
                    q[i].push(top);
                    continue;
                }
                if (!pq[i].empty() && row[q[i].size()].count(pq[i].top()) == 0) {
                    int top = pq[i].top();
                    pq[i].pop();
                    row[q[i].size()].insert(top);
                    q[i].push(top);
                    continue;
                }
                break;
            }
        }
        printf("%d %d\n", turns, upgrades);
    }
}


#include <bits/stdc++.h>
#define pb(x) push_back(x)

typedef long long ll;

using namespace std;

vector<int> g[10001];

int main(){
    int n; cin>>n;
    ll a[n];
    int dl[n];
    int dist=1e6;
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(a[i]==0)
            dist=0;
        dl[i]=dist++;
    }

    int dr[n];
    dist=1e6;
    for(int i=n-1; i>=0; i--){
        if(!a[i])
            dist=0;
        dr[i]=dist++;
    }

    for(int i=0; i<n; i++){
        cout<<min(dl[i], dr[i])<<" ";
    }

    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define oioi printf("oioi\n")
#define eoq cout << "eoq" << '\n'
#define CLS while (getchar () != '\n')
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll, ll> ii;
typedef pair<double, double> dd;
typedef vector<ll> vi;
typedef vector<ii> vii;
const int dx[] = { 0, 1, -1, 0, 1, -1, -1,  1};
const int dy[] = {-1, 0,  0, 1, 1,  1, -1, -1};
const int N = 0;
const int MOD = 0;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

int main () {

	int n;
	cin >> n;
	vector<int> pos;
	vector<int> :: iterator it;
	int v[200010];
	int x;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		v[i] = x;
		if(x==0) pos.pb(i);
	}

	for (int i = 0; i < n; i++)
	{
		if(v[i]==0) cout << "0 ";
		else{
			int a = 1e9, b = 1e9;
			it = lower_bound(pos.begin(), pos.end(), i);
			a = *it;
			if(it!=pos.begin()){
				it--;
				b = *it;
				cout << min(abs(a-i), abs(b-i)) << " ";
			}else cout << abs(a-i) << " ";

		}
	}
	cout << "\n";

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define oioi printf("oioi\n")
#define eoq cout << "eoq" << '\n'
#define CLS while (getchar () != '\n')
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<ll, ll> ii;
typedef pair<double, double> dd;
typedef vector<ll> vi;
typedef vector<ii> vii;
const int dx[] = { 0, 1, -1, 0, 1, -1, -1,  1};
const int dy[] = {-1, 0,  0, 1, 1,  1, -1, -1};
const int N = 0;
const int MOD = 0;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

int main () {

	int n;
	cin >> n;
	vector<int> pos;
	vector<int> :: iterator it;
	int v[200010];
	int x;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		v[i] = x;
		if(x==0) pos.pb(i);
	}

	for (int i = 0; i < n; i++)
	{
		if(v[i]==0) cout << "0 ";
		else{
			int a = 1e9, b = 1e9;
			it = lower_bound(pos.begin(), pos.end(), i);
			a = *it;
			if(it!=pos.begin()){
				it--;
				b = *it;
			}
			cout << min(abs(a-i), abs(b-i)) << " ";
		}
	}
	cout << "\n";

	return 0;
}


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

#define sz(a) (int)(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,c) for(auto it=c.begin();it!=c.end();it++)
#define fr(i,n)	for(int i=0;i<n;i++)
#define present(c,x) (c.find(x)!=c.end()) //for set/map etc.
#define cpresent(c,x) (find(all(c),x)!=c.end())
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pair<int,int>> vp;
int N=100001;
int mod=1e9+7;
int min(int a,int b){if(a<b) return a; else return b;}
int max(int a,int b){if(a>b) return a; else return b;}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int p, int q){if(p%q==0) return q; else{return gcd(q,p%q);}}
bool comp(int a, int b)
{
    return (a < b);
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       int x1,y1,x2,y2;
       cin>>x1>>y1>>x2>>y2;
        cout<<(x2-x1)*(y2-y1)+1;

        cout<<endl;
    }
    return 0;
}


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

#define sz(a) (int)(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,c) for(auto it=c.begin();it!=c.end();it++)
#define fr(i,n)	for(int i=0;i<n;i++)
#define present(c,x) (c.find(x)!=c.end()) //for set/map etc.
#define cpresent(c,x) (find(all(c),x)!=c.end())
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pair<int,int>> vp;
int N=100001;
int mod=1e9+7;
int min(int a,int b){if(a<b) return a; else return b;}
int max(int a,int b){if(a>b) return a; else return b;}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int p, int q){if(p%q==0) return q; else{return gcd(q,p%q);}}
bool comp(int a, int b)
{
    return (a < b);
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       long long x1,y1,x2,y2,ans;
       cin>>x1>>y1>>x2>>y2;
       ans =long((x2-x1)*(y2-y1));
        cout<<ans+1;

        cout<<endl;
    }
    return 0;
}


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

#define sz(a) (int)(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,c) for(auto it=c.begin();it!=c.end();it++)
#define fr(i,n)	for(int i=0;i<n;i++)
#define present(c,x) (c.find(x)!=c.end()) //for set/map etc.
#define cpresent(c,x) (find(all(c),x)!=c.end())
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pair<int,int>> vp;
int N=100001;
int mod=1e9+7;
int min(int a,int b){if(a<b) return a; else return b;}
int max(int a,int b){if(a>b) return a; else return b;}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int p, int q){if(p%q==0) return q; else{return gcd(q,p%q);}}
bool comp(int a, int b)
{
    return (a < b);
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       int x1,y1,x2,y2;
       cin>>x1>>y1>>x2>>y2;
        cout<<(x2-x1)*(y2-y1)+1;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
typedef pair<int, int>             pii;
typedef pair<pii, int>              piii;
typedef pair<long long, long long> pll;
typedef pair<pll, long long>        plll;
typedef vector<int>                vi;
typedef vector<vector<int>>        vvi;
typedef vector<long long>          vl;
typedef vector<vector<long long>>  vll;
typedef vector<pii>                vpii;
typedef vector<piii>               vpiii;
typedef vector<pll>                vpll;
typedef vector<plll>               vplll;
typedef vector<vector<plll>>       vvplll;
typedef vector<vector<pll>>        vvpll;
typedef vector<vector<piii>>       vvpiii;
typedef vector<vector<pii>>        vvpii;
#define pb push_back
#define mp make_pair
#define data data_
#define endl "\n"

set<int> numbers;

int board[101][101];

__int128 sum_n(__int128 last){
	return (1 + last) * last / 2;
}

__int128 sum_n(__int128 from, __int128 to){
	return sum_n(to) - sum_n(from-1);
}

__int128 sum_n_squared(__int128 last){
	return last * (last + 1) * (2*last + 1) / 6;
}

__int128 sum_n_squared(__int128 from, __int128 to){
	return sum_n_squared(to) - sum_n_squared(from - 1);
}

int main(){
	optimizar_io;
	int T;
	cin >> T;
	for (int t = 0; t < T; t++){
		int v_i = 0;
		for (int i = 1; i <= 100; i++){
			v_i += i;
			int v = v_i;
			for (int j = 1; j <= 100; j++){
				board[i][j] = v;
				v += (i + j - 1);
			}
		}
		int x1_, y1_, x2_, y2_;
		cin >> x1_ >> y1_ >> x2_ >> y2_;
		__int128 x1, y1, x2, y2;
		x1 = x1_;
		x2 = x2_;
		y1 = y1_;
		y2 = y2_;
		if ((x1 == x2) || (y1 == y2)){
			cout << 1 << endl;
		} else {
			__int128 sum1 = 0, sum2 = 0;
			__int128 init = (x1 + y1 - 1);
			//Sumamos parte inferior y superior
			sum1 = init * sum_n(x2 - x1) + sum_n_squared(x2 - x1) / 2 - sum_n(x2 - x1) / 2;
			//cout << "Sum1: " << (long long) sum1 << endl;
			init = (x1 + y2 - 1);
			__int128 dif = sum_n(x1 + y1, x1 + y1 + y2 - y1 - 1);
			sum2 = init * sum_n(x2 - x1) + sum_n_squared(x2 - x1) / 2 - sum_n(x2 - x1) / 2 + dif * (x2 - x1);
			//cout << "Sum2: " << (long long) sum2 << endl;
			//Sumamos parte derecha e izquierda
			init = (x1 + y1);
			sum2 += init * sum_n(y2 - y1) + sum_n_squared(y2 - y1) / 2 - sum_n(y2 - y1) / 2;
			//cout << "Sum2: " << (long long) sum2 << endl;
			init = (x2 + y1);
			dif = sum_n(y1 + x1 - 1, y1 + x1 + x2 - x1 - 2);
			//cout << "Dif: " << (long long) dif << endl;
			sum1 += init * sum_n(y2 - y1) + sum_n_squared(y2 - y1) / 2 - sum_n(y2 - y1) / 2 + dif * (y2 - y1);
			__int128 sol = (sum2 - sum1 + 1);
			//cout << "Sum1: " << (long long) sum1 << endl;
			cout << (long long) sol << endl;

		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int base = 1000000000;
const int base_digits = 9;
struct bigint {
	vector<int> a;
	int sign;
	/*<arpa>*/
	int size(){
		if(a.empty())return 0;
		int ans=(a.size()-1)*base_digits;
		int ca=a.back();
		while(ca)
			ans++,ca/=10;
		return ans;
	}
	bigint operator ^(const bigint &v){
		bigint ans=1,a=*this,b=v;
		while(!b.isZero()){
			if(b%2)
				ans*=a;
			a*=a,b/=2;
		}
		return ans;
	}
	string to_string(){
		stringstream ss;
		ss << *this;
		string s;
		ss >> s;
		return s;
	}
	int sumof(){
		string s = to_string();
		int ans = 0;
		for(auto c : s)  ans += c - '0';
		return ans;
	}
	/*</arpa>*/
	bigint() :
		sign(1) {
	}

	bigint(long long v) {
		*this = v;
	}

	bigint(const string &s) {
		read(s);
	}

	void operator=(const bigint &v) {
		sign = v.sign;
		a = v.a;
	}

	void operator=(long long v) {
		sign = 1;
		a.clear();
		if (v < 0)
			sign = -1, v = -v;
		for (; v > 0; v = v / base)
			a.push_back(v % base);
	}

	bigint operator+(const bigint &v) const {
		if (sign == v.sign) {
			bigint res = v;

			for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) {
				if (i == (int) res.a.size())
					res.a.push_back(0);
				res.a[i] += carry + (i < (int) a.size() ? a[i] : 0);
				carry = res.a[i] >= base;
				if (carry)
					res.a[i] -= base;
			}
			return res;
		}
		return *this - (-v);
	}

	bigint operator-(const bigint &v) const {
		if (sign == v.sign) {
			if (abs() >= v.abs()) {
				bigint res = *this;
				for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
					res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
					carry = res.a[i] < 0;
					if (carry)
						res.a[i] += base;
				}
				res.trim();
				return res;
			}
			return -(v - *this);
		}
		return *this + (-v);
	}

	void operator*=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
			if (i == (int) a.size())
				a.push_back(0);
			long long cur = a[i] * (long long) v + carry;
			carry = (int) (cur / base);
			a[i] = (int) (cur % base);
			//asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
		}
		trim();
	}

	bigint operator*(int v) const {
		bigint res = *this;
		res *= v;
		return res;
	}

	void operator*=(long long v) {
		if (v < 0)
			sign = -sign, v = -v;
		if(v > base){
			*this = *this * (v / base) * base + *this * (v % base);
			return ;
		}
		for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
			if (i == (int) a.size())
				a.push_back(0);
			long long cur = a[i] * (long long) v + carry;
			carry = (int) (cur / base);
			a[i] = (int) (cur % base);
			//asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
		}
		trim();
	}

	bigint operator*(long long v) const {
		bigint res = *this;
		res *= v;
		return res;
	}

	friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {
		int norm = base / (b1.a.back() + 1);
		bigint a = a1.abs() * norm;
		bigint b = b1.abs() * norm;
		bigint q, r;
		q.a.resize(a.a.size());

		for (int i = a.a.size() - 1; i >= 0; i--) {
			r *= base;
			r += a.a[i];
			int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
			int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
			int d = ((long long) base * s1 + s2) / b.a.back();
			r -= b * d;
			while (r < 0)
				r += b, --d;
			q.a[i] = d;
		}

		q.sign = a1.sign * b1.sign;
		r.sign = a1.sign;
		q.trim();
		r.trim();
		return make_pair(q, r / norm);
	}

	bigint operator/(const bigint &v) const {
		return divmod(*this, v).first;
	}

	bigint operator%(const bigint &v) const {
		return divmod(*this, v).second;
	}

	void operator/=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
			long long cur = a[i] + rem * (long long) base;
			a[i] = (int) (cur / v);
			rem = (int) (cur % v);
		}
		trim();
	}

	bigint operator/(int v) const {
		bigint res = *this;
		res /= v;
		return res;
	}

	int operator%(int v) const {
		if (v < 0)
			v = -v;
		int m = 0;
		for (int i = a.size() - 1; i >= 0; --i)
			m = (a[i] + m * (long long) base) % v;
		return m * sign;
	}

	void operator+=(const bigint &v) {
		*this = *this + v;
	}
	void operator-=(const bigint &v) {
		*this = *this - v;
	}
	void operator*=(const bigint &v) {
		*this = *this * v;
	}
	void operator/=(const bigint &v) {
		*this = *this / v;
	}

	bool operator<(const bigint &v) const {
		if (sign != v.sign)
			return sign < v.sign;
		if (a.size() != v.a.size())
			return a.size() * sign < v.a.size() * v.sign;
		for (int i = a.size() - 1; i >= 0; i--)
			if (a[i] != v.a[i])
				return a[i] * sign < v.a[i] * sign;
		return false;
	}

	bool operator>(const bigint &v) const {
		return v < *this;
	}
	bool operator<=(const bigint &v) const {
		return !(v < *this);
	}
	bool operator>=(const bigint &v) const {
		return !(*this < v);
	}
	bool operator==(const bigint &v) const {
		return !(*this < v) && !(v < *this);
	}
	bool operator!=(const bigint &v) const {
		return *this < v || v < *this;
	}

	void trim() {
		while (!a.empty() && !a.back())
			a.pop_back();
		if (a.empty())
			sign = 1;
	}

	bool isZero() const {
		return a.empty() || (a.size() == 1 && !a[0]);
	}

	bigint operator-() const {
		bigint res = *this;
		res.sign = -sign;
		return res;
	}

	bigint abs() const {
		bigint res = *this;
		res.sign *= res.sign;
		return res;
	}

	long long longValue() const {
		long long res = 0;
		for (int i = a.size() - 1; i >= 0; i--)
			res = res * base + a[i];
		return res * sign;
	}

	friend bigint gcd(const bigint &a, const bigint &b) {
		return b.isZero() ? a : gcd(b, a % b);
	}
	friend bigint lcm(const bigint &a, const bigint &b) {
		return a / gcd(a, b) * b;
	}

	void read(const string &s) {
		sign = 1;
		a.clear();
		int pos = 0;
		while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
			if (s[pos] == '-')
				sign = -sign;
			++pos;
		}
		for (int i = s.size() - 1; i >= pos; i -= base_digits) {
			int x = 0;
			for (int j = max(pos, i - base_digits + 1); j <= i; j++)
				x = x * 10 + s[j] - '0';
			a.push_back(x);
		}
		trim();
	}

	friend istream& operator>>(istream &stream, bigint &v) {
		string s;
		stream >> s;
		v.read(s);
		return stream;
	}

	friend ostream& operator<<(ostream &stream, const bigint &v) {
		if (v.sign == -1)
			stream << '-';
		stream << (v.a.empty() ? 0 : v.a.back());
		for (int i = (int) v.a.size() - 2; i >= 0; --i)
			stream << setw(base_digits) << setfill('0') << v.a[i];
		return stream;
	}

	static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
		vector<long long> p(max(old_digits, new_digits) + 1);
		p[0] = 1;
		for (int i = 1; i < (int) p.size(); i++)
			p[i] = p[i - 1] * 10;
		vector<int> res;
		long long cur = 0;
		int cur_digits = 0;
		for (int i = 0; i < (int) a.size(); i++) {
			cur += a[i] * p[cur_digits];
			cur_digits += old_digits;
			while (cur_digits >= new_digits) {
				res.push_back(int(cur % p[new_digits]));
				cur /= p[new_digits];
				cur_digits -= new_digits;
			}
		}
		res.push_back((int) cur);
		while (!res.empty() && !res.back())
			res.pop_back();
		return res;
	}

	typedef vector<long long> vll;

	static vll karatsubaMultiply(const vll &a, const vll &b) {
		int n = a.size();
		vll res(n + n);
		if (n <= 32) {
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					res[i + j] += a[i] * b[j];
			return res;
		}

		int k = n >> 1;
		vll a1(a.begin(), a.begin() + k);
		vll a2(a.begin() + k, a.end());
		vll b1(b.begin(), b.begin() + k);
		vll b2(b.begin() + k, b.end());

		vll a1b1 = karatsubaMultiply(a1, b1);
		vll a2b2 = karatsubaMultiply(a2, b2);

		for (int i = 0; i < k; i++)
			a2[i] += a1[i];
		for (int i = 0; i < k; i++)
			b2[i] += b1[i];

		vll r = karatsubaMultiply(a2, b2);
		for (int i = 0; i < (int) a1b1.size(); i++)
			r[i] -= a1b1[i];
		for (int i = 0; i < (int) a2b2.size(); i++)
			r[i] -= a2b2[i];

		for (int i = 0; i < (int) r.size(); i++)
			res[i + k] += r[i];
		for (int i = 0; i < (int) a1b1.size(); i++)
			res[i] += a1b1[i];
		for (int i = 0; i < (int) a2b2.size(); i++)
			res[i + n] += a2b2[i];
		return res;
	}

	bigint operator*(const bigint &v) const {
		vector<int> a6 = convert_base(this->a, base_digits, 6);
		vector<int> b6 = convert_base(v.a, base_digits, 6);
		vll a(a6.begin(), a6.end());
		vll b(b6.begin(), b6.end());
		while (a.size() < b.size())
			a.push_back(0);
		while (b.size() < a.size())
			b.push_back(0);
		while (a.size() & (a.size() - 1))
			a.push_back(0), b.push_back(0);
		vll c = karatsubaMultiply(a, b);
		bigint res;
		res.sign = sign * v.sign;
		for (int i = 0, carry = 0; i < (int) c.size(); i++) {
			long long cur = c[i] + carry;
			res.a.push_back((int) (cur % 1000000));
			carry = (int) (cur / 1000000);
		}
		res.a = convert_base(res.a, 6, base_digits);
		res.trim();
		return res;
	}
};
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
typedef pair<int, int>             pii;
typedef pair<pii, int>              piii;
typedef pair<long long, long long> pll;
typedef pair<pll, long long>        plll;
typedef vector<int>                vi;
typedef vector<vector<int>>        vvi;
typedef vector<long long>          vl;
typedef vector<vector<long long>>  vll;
typedef vector<pii>                vpii;
typedef vector<piii>               vpiii;
typedef vector<pll>                vpll;
typedef vector<plll>               vplll;
typedef vector<vector<plll>>       vvplll;
typedef vector<vector<pll>>        vvpll;
typedef vector<vector<piii>>       vvpiii;
typedef vector<vector<pii>>        vvpii;
#define pb push_back
#define mp make_pair
#define data data_
#define endl "\n"

set<int> numbers;

bigint sum_n(bigint last){
	return (last + 1ll) * last / 2ll;
}

bigint sum_n(bigint from, bigint to){
	return sum_n(to) - sum_n(from-1ll);
}

bigint sum_n_squared(bigint last){
	return last * (last + 1ll) * (last*2ll + 1ll) / 6ll;
}

bigint sum_n_squared(bigint from, bigint to){
	return sum_n_squared(to) - sum_n_squared(from - 1ll);
}

int main(){
	optimizar_io;
	int T;
	cin >> T;
	bigint x1, y1, x2, y2;
	for (int t = 0; t < T; t++){
		int v_i = 0;
		int x1_, y1_, x2_, y2_;
		cin >> x1_ >> y1_ >> x2_ >> y2_;
		x1 = x1_;
		x2 = x2_;
		y1 = y1_;
		y2 = y2_;
		if ((x1 == x2) || (y1 == y2)){
			cout << 1 << endl;
		} else {
			bigint sum1 = 0, sum2 = 0;
			bigint init = (x1 + y1 - 1ll);
			//Sumamos parte inferior y superior
			sum1 = init * sum_n(x2 - x1) + sum_n_squared(x2 - x1) / 2ll - sum_n(x2 - x1) / 2ll;
			//cout << "Sum1: " << (long long) sum1 << endl;
			init = (x1 + y2 - 1);
			bigint dif = sum_n(x1 + y1, x1 + y1 + y2 - y1 - 1ll);
			sum2 = init * sum_n(x2 - x1) + sum_n_squared(x2 - x1) / 2ll - sum_n(x2 - x1) / 2ll + dif * (x2 - x1);
			//cout << "Sum2: " << (long long) sum2 << endl;
			//Sumamos parte derecha e izquierda
			init = (x1 + y1);
			sum2 += init * sum_n(y2 - y1) + sum_n_squared(y2 - y1) / 2ll - sum_n(y2 - y1) / 2ll;
			//cout << "Sum2: " << (long long) sum2 << endl;
			init = (x2 + y1);
			dif = sum_n(y1 + x1 - 1ll, y1 + x1 + x2 - x1 - 2ll);
			//cout << "Dif: " << (long long) dif << endl;
			sum1 += init * sum_n(y2 - y1) + sum_n_squared(y2 - y1) / 2ll - sum_n(y2 - y1) / 2ll + dif * (y2 - y1);
			bigint sol = (sum2 - sum1 + 1ll);
			//cout << "Sum1: " << (long long) sum1 << endl;
			cout << sol << endl;
		}
	}
	return 0;
}


//Esta forma es correcta pero no da en tiempo por usar bigint.
//En lugar de calcular los numeros, solo necesitamos la diferencia.
//Nos podemos dar cuenta que el camino de menor costo es ir primero a la derecha
//y luego abajo, ya que tenemos que pasar por cada diagonal.
//Luego podemos buscar una forma de incrementar el camino en 1, y una forma
//es en el primer punto en que bajamos (que no sea la primera columna), lo modificamos
//para que baje justo antes. Con eso incrementamos y podemos ver que el numero de cambios
//que hara hasta formas el camino final es (x2 - x1) * (y2 - y1) + 1

#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
typedef pair<int, int>             pii;
typedef pair<pii, int>              piii;
typedef pair<long long, long long> pll;
typedef pair<pll, long long>        plll;
typedef vector<int>                vi;
typedef vector<vector<int>>        vvi;
typedef vector<long long>          vl;
typedef vector<vector<long long>>  vll;
typedef vector<pii>                vpii;
typedef vector<piii>               vpiii;
typedef vector<pll>                vpll;
typedef vector<plll>               vplll;
typedef vector<vector<plll>>       vvplll;
typedef vector<vector<pll>>        vvpll;
typedef vector<vector<piii>>       vvpiii;
typedef vector<vector<pii>>        vvpii;
#define pb push_back
#define mp make_pair
#define data data_
#define endl "\n"

__int128 sum_n(__int128 last){
	return (last + 1ll) * last / 2ll;
}

__int128 sum_n(__int128 from, __int128 to){
	return sum_n(to) - sum_n(from-1ll);
}

__int128 sum_n_squared(__int128 last){
	return last * (last + 1ll) * (last*2ll + 1ll) / 6ll;
}

__int128 sum_n_squared(__int128 from, __int128 to){
	return sum_n_squared(to) - sum_n_squared(from - 1ll);
}

int main(){
	optimizar_io;
	int T;
	cin >> T;
	for (int t = 0; t < T; t++){
		long long x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		cout << (x2 - x1) * (y2 - y1) + 1 << endl;
	}
	return 0;
}


//Esta forma es correcta pero no da en tiempo por usar bigint.
//En lugar de calcular los numeros, solo necesitamos la diferencia.
//Nos podemos dar cuenta que el camino de menor costo es ir primero a la derecha
//y luego abajo, ya que tenemos que pasar por cada diagonal.
//Luego podemos buscar una forma de incrementar el camino en 1, y una forma
//es en el primer punto en que bajamos (que no sea la primera columna), lo modificamos
//para que baje justo antes. Con eso incrementamos y podemos ver que el numero de cambios
//que hara hasta formas el camino final es (x2 - x1) * (y2 - y1) + 1

#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
typedef pair<int, int>             pii;
typedef pair<pii, int>              piii;
typedef pair<long long, long long> pll;
typedef pair<pll, long long>        plll;
typedef vector<int>                vi;
typedef vector<vector<int>>        vvi;
typedef vector<long long>          vl;
typedef vector<vector<long long>>  vll;
typedef vector<pii>                vpii;
typedef vector<piii>               vpiii;
typedef vector<pll>                vpll;
typedef vector<plll>               vplll;
typedef vector<vector<plll>>       vvplll;
typedef vector<vector<pll>>        vvpll;
typedef vector<vector<piii>>       vvpiii;
typedef vector<vector<pii>>        vvpii;
#define pb push_back
#define mp make_pair
#define data data_
#define endl "\n"

int main(){
	optimizar_io;
	int T;
	cin >> T;
	for (int t = 0; t < T; t++){
		long long x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		cout << (x2 - x1) * (y2 - y1) + 1 << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int base = 1000000000;
const int base_digits = 9;
struct bigint {
	vector<int> a;
	int sign;
	/*<arpa>*/
	int size(){
		if(a.empty())return 0;
		int ans=(a.size()-1)*base_digits;
		int ca=a.back();
		while(ca)
			ans++,ca/=10;
		return ans;
	}
	bigint operator ^(const bigint &v){
		bigint ans=1,a=*this,b=v;
		while(!b.isZero()){
			if(b%2)
				ans*=a;
			a*=a,b/=2;
		}
		return ans;
	}
	string to_string(){
		stringstream ss;
		ss << *this;
		string s;
		ss >> s;
		return s;
	}
	int sumof(){
		string s = to_string();
		int ans = 0;
		for(auto c : s)  ans += c - '0';
		return ans;
	}
	/*</arpa>*/
	bigint() :
		sign(1) {
	}

	bigint(long long v) {
		*this = v;
	}

	bigint(const string &s) {
		read(s);
	}

	void operator=(const bigint &v) {
		sign = v.sign;
		a = v.a;
	}

	void operator=(long long v) {
		sign = 1;
		a.clear();
		if (v < 0)
			sign = -1, v = -v;
		for (; v > 0; v = v / base)
			a.push_back(v % base);
	}

	bigint operator+(const bigint &v) const {
		if (sign == v.sign) {
			bigint res = v;

			for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) {
				if (i == (int) res.a.size())
					res.a.push_back(0);
				res.a[i] += carry + (i < (int) a.size() ? a[i] : 0);
				carry = res.a[i] >= base;
				if (carry)
					res.a[i] -= base;
			}
			return res;
		}
		return *this - (-v);
	}

	bigint operator-(const bigint &v) const {
		if (sign == v.sign) {
			if (abs() >= v.abs()) {
				bigint res = *this;
				for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
					res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
					carry = res.a[i] < 0;
					if (carry)
						res.a[i] += base;
				}
				res.trim();
				return res;
			}
			return -(v - *this);
		}
		return *this + (-v);
	}

	void operator*=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
			if (i == (int) a.size())
				a.push_back(0);
			long long cur = a[i] * (long long) v + carry;
			carry = (int) (cur / base);
			a[i] = (int) (cur % base);
			//asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
		}
		trim();
	}

	bigint operator*(int v) const {
		bigint res = *this;
		res *= v;
		return res;
	}

	void operator*=(long long v) {
		if (v < 0)
			sign = -sign, v = -v;
		if(v > base){
			*this = *this * (v / base) * base + *this * (v % base);
			return ;
		}
		for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
			if (i == (int) a.size())
				a.push_back(0);
			long long cur = a[i] * (long long) v + carry;
			carry = (int) (cur / base);
			a[i] = (int) (cur % base);
			//asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
		}
		trim();
	}

	bigint operator*(long long v) const {
		bigint res = *this;
		res *= v;
		return res;
	}

	friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {
		int norm = base / (b1.a.back() + 1);
		bigint a = a1.abs() * norm;
		bigint b = b1.abs() * norm;
		bigint q, r;
		q.a.resize(a.a.size());

		for (int i = a.a.size() - 1; i >= 0; i--) {
			r *= base;
			r += a.a[i];
			int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
			int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
			int d = ((long long) base * s1 + s2) / b.a.back();
			r -= b * d;
			while (r < 0)
				r += b, --d;
			q.a[i] = d;
		}

		q.sign = a1.sign * b1.sign;
		r.sign = a1.sign;
		q.trim();
		r.trim();
		return make_pair(q, r / norm);
	}

	bigint operator/(const bigint &v) const {
		return divmod(*this, v).first;
	}

	bigint operator%(const bigint &v) const {
		return divmod(*this, v).second;
	}

	void operator/=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
			long long cur = a[i] + rem * (long long) base;
			a[i] = (int) (cur / v);
			rem = (int) (cur % v);
		}
		trim();
	}

	bigint operator/(int v) const {
		bigint res = *this;
		res /= v;
		return res;
	}

	int operator%(int v) const {
		if (v < 0)
			v = -v;
		int m = 0;
		for (int i = a.size() - 1; i >= 0; --i)
			m = (a[i] + m * (long long) base) % v;
		return m * sign;
	}

	void operator+=(const bigint &v) {
		*this = *this + v;
	}
	void operator-=(const bigint &v) {
		*this = *this - v;
	}
	void operator*=(const bigint &v) {
		*this = *this * v;
	}
	void operator/=(const bigint &v) {
		*this = *this / v;
	}

	bool operator<(const bigint &v) const {
		if (sign != v.sign)
			return sign < v.sign;
		if (a.size() != v.a.size())
			return a.size() * sign < v.a.size() * v.sign;
		for (int i = a.size() - 1; i >= 0; i--)
			if (a[i] != v.a[i])
				return a[i] * sign < v.a[i] * sign;
		return false;
	}

	bool operator>(const bigint &v) const {
		return v < *this;
	}
	bool operator<=(const bigint &v) const {
		return !(v < *this);
	}
	bool operator>=(const bigint &v) const {
		return !(*this < v);
	}
	bool operator==(const bigint &v) const {
		return !(*this < v) && !(v < *this);
	}
	bool operator!=(const bigint &v) const {
		return *this < v || v < *this;
	}

	void trim() {
		while (!a.empty() && !a.back())
			a.pop_back();
		if (a.empty())
			sign = 1;
	}

	bool isZero() const {
		return a.empty() || (a.size() == 1 && !a[0]);
	}

	bigint operator-() const {
		bigint res = *this;
		res.sign = -sign;
		return res;
	}

	bigint abs() const {
		bigint res = *this;
		res.sign *= res.sign;
		return res;
	}

	long long longValue() const {
		long long res = 0;
		for (int i = a.size() - 1; i >= 0; i--)
			res = res * base + a[i];
		return res * sign;
	}

	friend bigint gcd(const bigint &a, const bigint &b) {
		return b.isZero() ? a : gcd(b, a % b);
	}
	friend bigint lcm(const bigint &a, const bigint &b) {
		return a / gcd(a, b) * b;
	}

	void read(const string &s) {
		sign = 1;
		a.clear();
		int pos = 0;
		while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
			if (s[pos] == '-')
				sign = -sign;
			++pos;
		}
		for (int i = s.size() - 1; i >= pos; i -= base_digits) {
			int x = 0;
			for (int j = max(pos, i - base_digits + 1); j <= i; j++)
				x = x * 10 + s[j] - '0';
			a.push_back(x);
		}
		trim();
	}

	friend istream& operator>>(istream &stream, bigint &v) {
		string s;
		stream >> s;
		v.read(s);
		return stream;
	}

	friend ostream& operator<<(ostream &stream, const bigint &v) {
		if (v.sign == -1)
			stream << '-';
		stream << (v.a.empty() ? 0 : v.a.back());
		for (int i = (int) v.a.size() - 2; i >= 0; --i)
			stream << setw(base_digits) << setfill('0') << v.a[i];
		return stream;
	}

	static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
		vector<long long> p(max(old_digits, new_digits) + 1);
		p[0] = 1;
		for (int i = 1; i < (int) p.size(); i++)
			p[i] = p[i - 1] * 10;
		vector<int> res;
		long long cur = 0;
		int cur_digits = 0;
		for (int i = 0; i < (int) a.size(); i++) {
			cur += a[i] * p[cur_digits];
			cur_digits += old_digits;
			while (cur_digits >= new_digits) {
				res.push_back(int(cur % p[new_digits]));
				cur /= p[new_digits];
				cur_digits -= new_digits;
			}
		}
		res.push_back((int) cur);
		while (!res.empty() && !res.back())
			res.pop_back();
		return res;
	}

	typedef vector<long long> vll;

	static vll karatsubaMultiply(const vll &a, const vll &b) {
		int n = a.size();
		vll res(n + n);
		if (n <= 32) {
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					res[i + j] += a[i] * b[j];
			return res;
		}

		int k = n >> 1;
		vll a1(a.begin(), a.begin() + k);
		vll a2(a.begin() + k, a.end());
		vll b1(b.begin(), b.begin() + k);
		vll b2(b.begin() + k, b.end());

		vll a1b1 = karatsubaMultiply(a1, b1);
		vll a2b2 = karatsubaMultiply(a2, b2);

		for (int i = 0; i < k; i++)
			a2[i] += a1[i];
		for (int i = 0; i < k; i++)
			b2[i] += b1[i];

		vll r = karatsubaMultiply(a2, b2);
		for (int i = 0; i < (int) a1b1.size(); i++)
			r[i] -= a1b1[i];
		for (int i = 0; i < (int) a2b2.size(); i++)
			r[i] -= a2b2[i];

		for (int i = 0; i < (int) r.size(); i++)
			res[i + k] += r[i];
		for (int i = 0; i < (int) a1b1.size(); i++)
			res[i] += a1b1[i];
		for (int i = 0; i < (int) a2b2.size(); i++)
			res[i + n] += a2b2[i];
		return res;
	}

	bigint operator*(const bigint &v) const {
		vector<int> a6 = convert_base(this->a, base_digits, 6);
		vector<int> b6 = convert_base(v.a, base_digits, 6);
		vll a(a6.begin(), a6.end());
		vll b(b6.begin(), b6.end());
		while (a.size() < b.size())
			a.push_back(0);
		while (b.size() < a.size())
			b.push_back(0);
		while (a.size() & (a.size() - 1))
			a.push_back(0), b.push_back(0);
		vll c = karatsubaMultiply(a, b);
		bigint res;
		res.sign = sign * v.sign;
		for (int i = 0, carry = 0; i < (int) c.size(); i++) {
			long long cur = c[i] + carry;
			res.a.push_back((int) (cur % 1000000));
			carry = (int) (cur / 1000000);
		}
		res.a = convert_base(res.a, 6, base_digits);
		res.trim();
		return res;
	}
};
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
typedef pair<int, int>             pii;
typedef pair<pii, int>              piii;
typedef pair<long long, long long> pll;
typedef pair<pll, long long>        plll;
typedef vector<int>                vi;
typedef vector<vector<int>>        vvi;
typedef vector<long long>          vl;
typedef vector<vector<long long>>  vll;
typedef vector<pii>                vpii;
typedef vector<piii>               vpiii;
typedef vector<pll>                vpll;
typedef vector<plll>               vplll;
typedef vector<vector<plll>>       vvplll;
typedef vector<vector<pll>>        vvpll;
typedef vector<vector<piii>>       vvpiii;
typedef vector<vector<pii>>        vvpii;
#define pb push_back
#define mp make_pair
#define data data_
#define endl "\n"

set<int> numbers;

bigint sum_n(bigint last){
	return (last + 1ll) * last / 2ll;
}

bigint sum_n(bigint from, bigint to){
	return sum_n(to) - sum_n(from-1ll);
}

bigint sum_n_squared(bigint last){
	return last * (last + 1ll) * (last*2ll + 1ll) / 6ll;
}

bigint sum_n_squared(bigint from, bigint to){
	return sum_n_squared(to) - sum_n_squared(from - 1ll);
}

int main(){
	optimizar_io;
	int T;
	cin >> T;
	bigint x1, y1, x2, y2, sum1, sum2, init, dif, sol;
	for (int t = 0; t < T; t++){
		int v_i = 0;
		int x1_, y1_, x2_, y2_;
		cin >> x1_ >> y1_ >> x2_ >> y2_;
		x1 = x1_;
		x2 = x2_;
		y1 = y1_;
		y2 = y2_;
		if ((x1 == x2) || (y1 == y2)){
			cout << 1 << endl;
		} else {
			sum1 = 0;
			sum2 = 0;
			init = (x1 + y1 - 1ll);
			//Sumamos parte inferior y superior
			sum1 = init * sum_n(x2 - x1) + sum_n_squared(x2 - x1) / 2ll - sum_n(x2 - x1) / 2ll;
			//cout << "Sum1: " << (long long) sum1 << endl;
			init = (x1 + y2 - 1);
			dif = sum_n(x1 + y1, x1 + y1 + y2 - y1 - 1ll);
			sum2 = init * sum_n(x2 - x1) + sum_n_squared(x2 - x1) / 2ll - sum_n(x2 - x1) / 2ll + dif * (x2 - x1);
			//cout << "Sum2: " << (long long) sum2 << endl;
			//Sumamos parte derecha e izquierda
			init = (x1 + y1);
			sum2 += init * sum_n(y2 - y1) + sum_n_squared(y2 - y1) / 2ll - sum_n(y2 - y1) / 2ll;
			//cout << "Sum2: " << (long long) sum2 << endl;
			init = (x2 + y1);
			dif = sum_n(y1 + x1 - 1ll, y1 + x1 + x2 - x1 - 2ll);
			//cout << "Dif: " << (long long) dif << endl;
			sum1 += init * sum_n(y2 - y1) + sum_n_squared(y2 - y1) / 2ll - sum_n(y2 - y1) / 2ll + dif * (y2 - y1);
			sol = (sum2 - sum1 + 1ll);
			//cout << "Sum1: " << (long long) sum1 << endl;
			cout << sol << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int base = 1000000000;
const int base_digits = 9;
struct bigint {
	vector<int> a;
	int sign;
	/*<arpa>*/
	int size(){
		if(a.empty())return 0;
		int ans=(a.size()-1)*base_digits;
		int ca=a.back();
		while(ca)
			ans++,ca/=10;
		return ans;
	}
	bigint operator ^(const bigint &v){
		bigint ans=1,a=*this,b=v;
		while(!b.isZero()){
			if(b%2)
				ans*=a;
			a*=a,b/=2;
		}
		return ans;
	}
	string to_string(){
		stringstream ss;
		ss << *this;
		string s;
		ss >> s;
		return s;
	}
	int sumof(){
		string s = to_string();
		int ans = 0;
		for(auto c : s)  ans += c - '0';
		return ans;
	}
	/*</arpa>*/
	bigint() :
		sign(1) {
	}

	bigint(long long v) {
		*this = v;
	}

	bigint(const string &s) {
		read(s);
	}

	void operator=(const bigint &v) {
		sign = v.sign;
		a = v.a;
	}

	void operator=(long long v) {
		sign = 1;
		a.clear();
		if (v < 0)
			sign = -1, v = -v;
		for (; v > 0; v = v / base)
			a.push_back(v % base);
	}

	bigint operator+(const bigint &v) const {
		if (sign == v.sign) {
			bigint res = v;

			for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) {
				if (i == (int) res.a.size())
					res.a.push_back(0);
				res.a[i] += carry + (i < (int) a.size() ? a[i] : 0);
				carry = res.a[i] >= base;
				if (carry)
					res.a[i] -= base;
			}
			return res;
		}
		return *this - (-v);
	}

	bigint operator-(const bigint &v) const {
		if (sign == v.sign) {
			if (abs() >= v.abs()) {
				bigint res = *this;
				for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
					res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
					carry = res.a[i] < 0;
					if (carry)
						res.a[i] += base;
				}
				res.trim();
				return res;
			}
			return -(v - *this);
		}
		return *this + (-v);
	}

	void operator*=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
			if (i == (int) a.size())
				a.push_back(0);
			long long cur = a[i] * (long long) v + carry;
			carry = (int) (cur / base);
			a[i] = (int) (cur % base);
			//asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
		}
		trim();
	}

	bigint operator*(int v) const {
		bigint res = *this;
		res *= v;
		return res;
	}

	void operator*=(long long v) {
		if (v < 0)
			sign = -sign, v = -v;
		if(v > base){
			*this = *this * (v / base) * base + *this * (v % base);
			return ;
		}
		for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
			if (i == (int) a.size())
				a.push_back(0);
			long long cur = a[i] * (long long) v + carry;
			carry = (int) (cur / base);
			a[i] = (int) (cur % base);
			//asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
		}
		trim();
	}

	bigint operator*(long long v) const {
		bigint res = *this;
		res *= v;
		return res;
	}

	friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {
		int norm = base / (b1.a.back() + 1);
		bigint a = a1.abs() * norm;
		bigint b = b1.abs() * norm;
		bigint q, r;
		q.a.resize(a.a.size());

		for (int i = a.a.size() - 1; i >= 0; i--) {
			r *= base;
			r += a.a[i];
			int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
			int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
			int d = ((long long) base * s1 + s2) / b.a.back();
			r -= b * d;
			while (r < 0)
				r += b, --d;
			q.a[i] = d;
		}

		q.sign = a1.sign * b1.sign;
		r.sign = a1.sign;
		q.trim();
		r.trim();
		return make_pair(q, r / norm);
	}

	bigint operator/(const bigint &v) const {
		return divmod(*this, v).first;
	}

	bigint operator%(const bigint &v) const {
		return divmod(*this, v).second;
	}

	void operator/=(int v) {
		if (v < 0)
			sign = -sign, v = -v;
		for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
			long long cur = a[i] + rem * (long long) base;
			a[i] = (int) (cur / v);
			rem = (int) (cur % v);
		}
		trim();
	}

	bigint operator/(int v) const {
		bigint res = *this;
		res /= v;
		return res;
	}

	int operator%(int v) const {
		if (v < 0)
			v = -v;
		int m = 0;
		for (int i = a.size() - 1; i >= 0; --i)
			m = (a[i] + m * (long long) base) % v;
		return m * sign;
	}

	void operator+=(const bigint &v) {
		*this = *this + v;
	}
	void operator-=(const bigint &v) {
		*this = *this - v;
	}
	void operator*=(const bigint &v) {
		*this = *this * v;
	}
	void operator/=(const bigint &v) {
		*this = *this / v;
	}

	bool operator<(const bigint &v) const {
		if (sign != v.sign)
			return sign < v.sign;
		if (a.size() != v.a.size())
			return a.size() * sign < v.a.size() * v.sign;
		for (int i = a.size() - 1; i >= 0; i--)
			if (a[i] != v.a[i])
				return a[i] * sign < v.a[i] * sign;
		return false;
	}

	bool operator>(const bigint &v) const {
		return v < *this;
	}
	bool operator<=(const bigint &v) const {
		return !(v < *this);
	}
	bool operator>=(const bigint &v) const {
		return !(*this < v);
	}
	bool operator==(const bigint &v) const {
		return !(*this < v) && !(v < *this);
	}
	bool operator!=(const bigint &v) const {
		return *this < v || v < *this;
	}

	void trim() {
		while (!a.empty() && !a.back())
			a.pop_back();
		if (a.empty())
			sign = 1;
	}

	bool isZero() const {
		return a.empty() || (a.size() == 1 && !a[0]);
	}

	bigint operator-() const {
		bigint res = *this;
		res.sign = -sign;
		return res;
	}

	bigint abs() const {
		bigint res = *this;
		res.sign *= res.sign;
		return res;
	}

	long long longValue() const {
		long long res = 0;
		for (int i = a.size() - 1; i >= 0; i--)
			res = res * base + a[i];
		return res * sign;
	}

	friend bigint gcd(const bigint &a, const bigint &b) {
		return b.isZero() ? a : gcd(b, a % b);
	}
	friend bigint lcm(const bigint &a, const bigint &b) {
		return a / gcd(a, b) * b;
	}

	void read(const string &s) {
		sign = 1;
		a.clear();
		int pos = 0;
		while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
			if (s[pos] == '-')
				sign = -sign;
			++pos;
		}
		for (int i = s.size() - 1; i >= pos; i -= base_digits) {
			int x = 0;
			for (int j = max(pos, i - base_digits + 1); j <= i; j++)
				x = x * 10 + s[j] - '0';
			a.push_back(x);
		}
		trim();
	}

	friend istream& operator>>(istream &stream, bigint &v) {
		string s;
		stream >> s;
		v.read(s);
		return stream;
	}

	friend ostream& operator<<(ostream &stream, const bigint &v) {
		if (v.sign == -1)
			stream << '-';
		stream << (v.a.empty() ? 0 : v.a.back());
		for (int i = (int) v.a.size() - 2; i >= 0; --i)
			stream << setw(base_digits) << setfill('0') << v.a[i];
		return stream;
	}

	static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
		vector<long long> p(max(old_digits, new_digits) + 1);
		p[0] = 1;
		for (int i = 1; i < (int) p.size(); i++)
			p[i] = p[i - 1] * 10;
		vector<int> res;
		long long cur = 0;
		int cur_digits = 0;
		for (int i = 0; i < (int) a.size(); i++) {
			cur += a[i] * p[cur_digits];
			cur_digits += old_digits;
			while (cur_digits >= new_digits) {
				res.push_back(int(cur % p[new_digits]));
				cur /= p[new_digits];
				cur_digits -= new_digits;
			}
		}
		res.push_back((int) cur);
		while (!res.empty() && !res.back())
			res.pop_back();
		return res;
	}

	typedef vector<long long> vll;

	static vll karatsubaMultiply(const vll &a, const vll &b) {
		int n = a.size();
		vll res(n + n);
		if (n <= 32) {
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					res[i + j] += a[i] * b[j];
			return res;
		}

		int k = n >> 1;
		vll a1(a.begin(), a.begin() + k);
		vll a2(a.begin() + k, a.end());
		vll b1(b.begin(), b.begin() + k);
		vll b2(b.begin() + k, b.end());

		vll a1b1 = karatsubaMultiply(a1, b1);
		vll a2b2 = karatsubaMultiply(a2, b2);

		for (int i = 0; i < k; i++)
			a2[i] += a1[i];
		for (int i = 0; i < k; i++)
			b2[i] += b1[i];

		vll r = karatsubaMultiply(a2, b2);
		for (int i = 0; i < (int) a1b1.size(); i++)
			r[i] -= a1b1[i];
		for (int i = 0; i < (int) a2b2.size(); i++)
			r[i] -= a2b2[i];

		for (int i = 0; i < (int) r.size(); i++)
			res[i + k] += r[i];
		for (int i = 0; i < (int) a1b1.size(); i++)
			res[i] += a1b1[i];
		for (int i = 0; i < (int) a2b2.size(); i++)
			res[i + n] += a2b2[i];
		return res;
	}

	bigint operator*(const bigint &v) const {
		vector<int> a6 = convert_base(this->a, base_digits, 6);
		vector<int> b6 = convert_base(v.a, base_digits, 6);
		vll a(a6.begin(), a6.end());
		vll b(b6.begin(), b6.end());
		while (a.size() < b.size())
			a.push_back(0);
		while (b.size() < a.size())
			b.push_back(0);
		while (a.size() & (a.size() - 1))
			a.push_back(0), b.push_back(0);
		vll c = karatsubaMultiply(a, b);
		bigint res;
		res.sign = sign * v.sign;
		for (int i = 0, carry = 0; i < (int) c.size(); i++) {
			long long cur = c[i] + carry;
			res.a.push_back((int) (cur % 1000000));
			carry = (int) (cur / 1000000);
		}
		res.a = convert_base(res.a, 6, base_digits);
		res.trim();
		return res;
	}
};
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
typedef pair<int, int>             pii;
typedef pair<pii, int>              piii;
typedef pair<long long, long long> pll;
typedef pair<pll, long long>        plll;
typedef vector<int>                vi;
typedef vector<vector<int>>        vvi;
typedef vector<long long>          vl;
typedef vector<vector<long long>>  vll;
typedef vector<pii>                vpii;
typedef vector<piii>               vpiii;
typedef vector<pll>                vpll;
typedef vector<plll>               vplll;
typedef vector<vector<plll>>       vvplll;
typedef vector<vector<pll>>        vvpll;
typedef vector<vector<piii>>       vvpiii;
typedef vector<vector<pii>>        vvpii;
#define pb push_back
#define mp make_pair
#define data data_
#define endl "\n"

set<int> numbers;

int board[101][101];

bigint sum_n(bigint last){
	return (last + 1ll) * last / 2ll;
}

bigint sum_n(bigint from, bigint to){
	return sum_n(to) - sum_n(from-1ll);
}

bigint sum_n_squared(bigint last){
	return last * (last + 1ll) * (last*2ll + 1ll) / 6ll;
}

bigint sum_n_squared(bigint from, bigint to){
	return sum_n_squared(to) - sum_n_squared(from - 1ll);
}

int main(){
	optimizar_io;
	int T;
	cin >> T;
	for (int t = 0; t < T; t++){
		int v_i = 0;
		for (int i = 1; i <= 100; i++){
			v_i += i;
			int v = v_i;
			for (int j = 1; j <= 100; j++){
				board[i][j] = v;
				v += (i + j - 1);
			}
		}
		int x1_, y1_, x2_, y2_;
		cin >> x1_ >> y1_ >> x2_ >> y2_;
		bigint x1, y1, x2, y2;
		x1 = x1_;
		x2 = x2_;
		y1 = y1_;
		y2 = y2_;
		if ((x1 == x2) || (y1 == y2)){
			cout << 1 << endl;
		} else {
			bigint sum1 = 0, sum2 = 0;
			bigint init = (x1 + y1 - 1ll);
			//Sumamos parte inferior y superior
			sum1 = init * sum_n(x2 - x1) + sum_n_squared(x2 - x1) / 2ll - sum_n(x2 - x1) / 2ll;
			//cout << "Sum1: " << (long long) sum1 << endl;
			init = (x1 + y2 - 1);
			bigint dif = sum_n(x1 + y1, x1 + y1 + y2 - y1 - 1ll);
			sum2 = init * sum_n(x2 - x1) + sum_n_squared(x2 - x1) / 2ll - sum_n(x2 - x1) / 2ll + dif * (x2 - x1);
			//cout << "Sum2: " << (long long) sum2 << endl;
			//Sumamos parte derecha e izquierda
			init = (x1 + y1);
			sum2 += init * sum_n(y2 - y1) + sum_n_squared(y2 - y1) / 2ll - sum_n(y2 - y1) / 2ll;
			//cout << "Sum2: " << (long long) sum2 << endl;
			init = (x2 + y1);
			dif = sum_n(y1 + x1 - 1ll, y1 + x1 + x2 - x1 - 2ll);
			//cout << "Dif: " << (long long) dif << endl;
			sum1 += init * sum_n(y2 - y1) + sum_n_squared(y2 - y1) / 2ll - sum_n(y2 - y1) / 2ll + dif * (y2 - y1);
			bigint sol = (sum2 - sum1 + 1ll);
			//cout << "Sum1: " << (long long) sum1 << endl;
			cout << sol << endl;
		}
	}
	return 0;
}


//Lo implemente con two points, creo que es mas sencillo implementarlo
//con busqueda binaria
#include <bits/stdc++.h>

using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
typedef pair<int, int>             pii;
typedef pair<pii, int>              piii;
typedef pair<long long, long long> pll;
typedef pair<pll, long long>        plll;
typedef vector<int>                vi;
typedef vector<vector<int>>        vvi;
typedef vector<long long>          vl;
typedef vector<vector<long long>>  vll;
typedef vector<pii>                vpii;
typedef vector<piii>               vpiii;
typedef vector<pll>                vpll;
typedef vector<plll>               vplll;
typedef vector<vector<plll>>       vvplll;
typedef vector<vector<pll>>        vvpll;
typedef vector<vector<piii>>       vvpiii;
typedef vector<vector<pii>>        vvpii;
#define pb push_back
#define mp make_pair
#define data data_
#define endl "\n"

int main(){
	optimizar_io;
	long long n, x;
	cin >> n >> x;
	long long orig_x = x;
	long long d[2*n + 1];
	long long days = 0;
	long long sumHugs = 0;
	for (int i = 1; i <= n; i++){
		cin >> d[i];
		days += d[i];
		sumHugs += (1 + d[i]) * d[i] / 2;
	}
	long long sol = 0;
	sol += sumHugs * (x / days);
	for (int i = n + 1; i <= 2 * n; i++){
		d[i] = d[i-n];
	}

	long long maxRem = 0;
	for (int check = 0; check < 2; check++){
		reverse(d + 1, d + 2 * n + 1);
		x = orig_x % days;
		long long firstIncomplete = n + 1;
		long long currentHugs = 0;
		while(x >= d[firstIncomplete]){
			x -= d[firstIncomplete];
			currentHugs += (1 + d[firstIncomplete]) * d[firstIncomplete] / 2;
			firstIncomplete--;
		}
		currentHugs += (d[firstIncomplete] + d[firstIncomplete] - x + 1) * x / 2;
		maxRem = max(maxRem, currentHugs);
		for (int option = n + 2; option <= 2 * n; option++){
			long long req = d[option];
			//Quitamos los del incompleto
			currentHugs -= (d[firstIncomplete] + d[firstIncomplete] - x + 1) * x / 2;
			firstIncomplete++;
			while((x < req) && (x != orig_x)){
				x += d[firstIncomplete];
				currentHugs -= (1 + d[firstIncomplete]) * d[firstIncomplete] / 2;
				firstIncomplete++;
			}
			x -= (min(req, x));
			if (orig_x >= d[option]){
				currentHugs += (d[option] + 1) * d[option] / 2;
				firstIncomplete--;
				currentHugs += (d[firstIncomplete] + d[firstIncomplete] - x + 1) * x / 2;
			} else {
				currentHugs += (d[option] + d[option] - orig_x + 1) * orig_x / 2;
				firstIncomplete = option;
				x = orig_x;
			}
			maxRem = max(maxRem, currentHugs);
		}
	}
	cout << sol + maxRem << endl;
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef __int128 ll;
typedef vector<int> vi;
const int INF = 1e9, MAXN = 100001;
const ll LINF = 1LL << 62;
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
void yesno(bool b) { b ? yes() : no(); }

ll prefsum(ll n) {
    return n*(n+1)/2;
}

ll entry(ll x, ll y) {
    return prefsum(x) + ( prefsum(x-1 + y-1) - prefsum(x-1) );
}

// sums inside col
ll colsum(ll x, ll y) {
    return x*(x*x + 3*x*y + 3*y*y - 6*y +5)/6;
}
ll colsum(ll x1, ll x2, ll y) {
    return colsum(x2, y) - colsum(x1-1, y);
}
// sums inside row
ll rowsum(ll x, ll y) {
    return y*(3*x*x + 3*x*y + y*y - 3*y + 2)/6;
}
ll rowsum(ll x, ll y1, ll y2) {
    return rowsum(x, y2) - rowsum(x, y1-1);
}

void solve() {
    long long x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    ll maxpath = colsum(x1,x2,y1) - entry(x2,y1) + rowsum(x2,y1,y2);
    ll minpath = rowsum(x1,y1,y2) - entry(x1,y2) + colsum(x1,x2,y2);

//    cerr << "maxpath = " << maxpath << ", minpath = " << minpath << endl;

    cout << (long long) (maxpath-minpath+1) << endl;
}

int main() {
/*
    for(int x1 = 1; x1 <= 5; x1++)
        for(int y1 = 1; y1 <= 5; y1++)
            for(int x2 = x1+1; x2 <= 5; x2++)
                for(int y2 = y1+1; y2 <= 5; y2++) {
                    ll maxpath = colsum(x1,x2,y1) - entry(x2,y1) + rowsum(x2,y1,y2);
                    ll minpath = rowsum(x1,y1,y2) - entry(x1,y2) + colsum(x1,x2,y2);
                    cout << "res("<<x1<<","<<y1<<","<<x2<<","<<y2<<"): " << maxpath << " " << minpath << endl;

                }

/*
    for(int i = 1; i <= 10; i++) {
        for(int j = 1; j <= 10; j++)
            cerr << entry(i,j) << " ";
        cerr << endl;
    }
*/
    int t;
    cin >> t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#define pb push_back
#define a__int128(v) v.begin(),v.end()
using namespace std;
typedef vector<int> vi;
const int INF = 1e9, MAXN = 100001;
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
void yesno(bool b) { b ? yes() : no(); }

__int128 prefsum(__int128 n) {
    return n*(n+1)/2;
}

__int128 entry(__int128 x, __int128 y) {
    return prefsum(x) + ( prefsum(x-1 + y-1) - prefsum(x-1) );
}

// sums inside col
__int128 colsum(__int128 x, __int128 y) {
    return x*(x*x + 3*x*y + 3*y*y - 6*y +5)/6;
}
__int128 colsum(__int128 x1, __int128 x2, __int128 y) {
    return colsum(x2, y) - colsum(x1-1, y);
}
// sums inside row
__int128 rowsum(__int128 x, __int128 y) {
    return y*(3*x*x + 3*x*y + y*y - 3*y + 2)/6;
}
__int128 rowsum(__int128 x, __int128 y1, __int128 y2) {
    return rowsum(x, y2) - rowsum(x, y1-1);
}

void solve() {
    long long x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    __int128 maxpath = colsum(x1,x2,y1) - entry(x2,y1) + rowsum(x2,y1,y2);
    __int128 minpath = rowsum(x1,y1,y2) - entry(x1,y2) + colsum(x1,x2,y2);

//    cerr << "maxpath = " << maxpath << ", minpath = " << minpath << endl;

    cout << (long long) (maxpath-minpath+1) << endl;
}

int main() {
/*
    for(int x1 = 1; x1 <= 5; x1++)
        for(int y1 = 1; y1 <= 5; y1++)
            for(int x2 = x1+1; x2 <= 5; x2++)
                for(int y2 = y1+1; y2 <= 5; y2++) {
                    __int128 maxpath = colsum(x1,x2,y1) - entry(x2,y1) + rowsum(x2,y1,y2);
                    __int128 minpath = rowsum(x1,y1,y2) - entry(x1,y2) + colsum(x1,x2,y2);
                    cout << "res("<<x1<<","<<y1<<","<<x2<<","<<y2<<"): " << maxpath << " " << minpath << endl;

                }

/*
    for(int i = 1; i <= 10; i++) {
        for(int j = 1; j <= 10; j++)
            cerr << entry(i,j) << " ";
        cerr << endl;
    }
*/
    int t;
    cin >> t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef long double lf;
typedef vector<int> vi;
const int INF = 1e9, MAXN = 100001;
const ll LINF = 1LL << 62;
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
void yesno(bool b) { b ? yes() : no(); }

void solve() {
    ll x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if(x1 == x2 || y1 == y2) {
        cout << 1 << endl;
        return;
    }
    cout << x2-x1 + y2-y1 << endl;
}

int main() {
    int t;
    cin >> t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef long double lf;
typedef vector<int> vi;
const int INF = 1e9, MAXN = 100001;
const ll LINF = 1LL << 62;
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
void yesno(bool b) { b ? yes() : no(); }

ll prefsum(ll n) {
    return n*(n+1)/2;
}

ll entry(ll x, ll y) {
    return prefsum(x) + ( prefsum(x-1 + y-1) - prefsum(x-1) );
}

// sums inside col
ll colsum(ll x, ll y) {
    return x*(x*x + 3*x*y + 3*y*y - 6*y +5)/6;
}
ll colsum(ll x1, ll x2, ll y) {
    return colsum(x2, y) - colsum(x1-1, y);
}
// sums inside row
ll rowsum(ll x, ll y) {
    return y*(3*x*x + 3*x*y + y*y - 3*y + 2)/6;
}
ll rowsum(ll x, ll y1, ll y2) {
    return rowsum(x, y2) - rowsum(x, y1-1);
}

void solve() {
    ll x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    ll maxpath = colsum(x1,x2,y1) - entry(x2,y1) + rowsum(x2,y1,y2);
    ll minpath = rowsum(x1,y1,y2) - entry(x1,y2) + colsum(x1,x2,y2);

//    cerr << "maxpath = " << maxpath << ", minpath = " << minpath << endl;

    cout << maxpath-minpath+1 << endl;
}

int main() {
/*
    for(int i = 1; i <= 10; i++) {
        for(int j = 1; j <= 10; j++)
            cerr << entry(i,j) << " ";
        cerr << endl;
    }
*/
    int t;
    cin >> t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef long double ll;
typedef vector<int> vi;
const int INF = 1e9, MAXN = 100001;
const ll LINF = 1LL << 62;
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
void yesno(bool b) { b ? yes() : no(); }

ll prefsum(ll n) {
    return n*(n+1)/2;
}

ll entry(ll x, ll y) {
    return prefsum(x) + ( prefsum(x-1 + y-1) - prefsum(x-1) );
}

// sums inside col
ll colsum(ll x, ll y) {
    return x*(x*x + 3*x*y + 3*y*y - 6*y +5)/6;
}
ll colsum(ll x1, ll x2, ll y) {
    return colsum(x2, y) - colsum(x1-1, y);
}
// sums inside row
ll rowsum(ll x, ll y) {
    return y*(3*x*x + 3*x*y + y*y - 3*y + 2)/6;
}
ll rowsum(ll x, ll y1, ll y2) {
    return rowsum(x, y2) - rowsum(x, y1-1);
}

void solve() {
    ll x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    ll maxpath = colsum(x1,x2,y1) - entry(x2,y1) + rowsum(x2,y1,y2);
    ll minpath = rowsum(x1,y1,y2) - entry(x1,y2) + colsum(x1,x2,y2);

//    cerr << "maxpath = " << maxpath << ", minpath = " << minpath << endl;

    cout << maxpath-minpath+1 << endl;
}

int main() {
/*
    for(int i = 1; i <= 10; i++) {
        for(int j = 1; j <= 10; j++)
            cerr << entry(i,j) << " ";
        cerr << endl;
    }
*/
    int t;
    cin >> t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
#define ll __int128
typedef vector<int> vi;
const int INF = 1e9, MAXN = 100001;
const ll LINF = 1LL << 62;
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
void yesno(bool b) { b ? yes() : no(); }

ll prefsum(ll n) {
    return n*(n+1)/2;
}

ll entry(ll x, ll y) {
    return prefsum(x) + ( prefsum(x-1 + y-1) - prefsum(x-1) );
}

// sums inside col
ll colsum(ll x, ll y) {
    return x*(x*x + 3*x*y + 3*y*y - 6*y +5)/6;
}
ll colsum(ll x1, ll x2, ll y) {
    return colsum(x2, y) - colsum(x1-1, y);
}
// sums inside row
ll rowsum(ll x, ll y) {
    return y*(3*x*x + 3*x*y + y*y - 3*y + 2)/6;
}
ll rowsum(ll x, ll y1, ll y2) {
    return rowsum(x, y2) - rowsum(x, y1-1);
}

void solve() {
    long long x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    ll maxpath = colsum(x1,x2,y1) - entry(x2,y1) + rowsum(x2,y1,y2);
    ll minpath = rowsum(x1,y1,y2) - entry(x1,y2) + colsum(x1,x2,y2);

//    cerr << "maxpath = " << maxpath << ", minpath = " << minpath << endl;

    cout << (long long) (maxpath-minpath+1) << endl;
}

int main() {
/*
    for(int x1 = 1; x1 <= 5; x1++)
        for(int y1 = 1; y1 <= 5; y1++)
            for(int x2 = x1+1; x2 <= 5; x2++)
                for(int y2 = y1+1; y2 <= 5; y2++) {
                    ll maxpath = colsum(x1,x2,y1) - entry(x2,y1) + rowsum(x2,y1,y2);
                    ll minpath = rowsum(x1,y1,y2) - entry(x1,y2) + colsum(x1,x2,y2);
                    cout << "res("<<x1<<","<<y1<<","<<x2<<","<<y2<<"): " << maxpath << " " << minpath << endl;

                }

/*
    for(int i = 1; i <= 10; i++) {
        for(int j = 1; j <= 10; j++)
            cerr << entry(i,j) << " ";
        cerr << endl;
    }
*/
    int t;
    cin >> t;
    while(t--)
        solve();
}


// --------------------|
// Sachinam Srivastava |
//     26-05-2020      |
//---------------------|

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

#define ll long long

ll numberOfPaths(ll m, ll n)
{
    ll path = 1;
    for (ll i = n; i < (m + n - 1); i++) {
        path *= i;
        path /= (i - n + 1);
    }
    return path;
}

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        cout<<numberOfPaths(c-a+1,d-b+1)<<endl;
    }
}


// --------------------|
// Sachinam Srivastava |
//     26-05-2020      |
//---------------------|

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

#define ll unsigned long long

ll numberOfPaths(ll m, ll n)
{
    ll path = 1;
    for (ll i = n; i < (m + n - 1); i++) {
        path *= i;
        path /= (i - n + 1);
    }
    return path;
}

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        cout<<numberOfPaths(c-a+1,d-b+1)<<endl;
    }
}


// --------------------|
// Sachinam Srivastava |
//     26-05-2020      |
//---------------------|

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

#define ll unsigned long long

ll numberOfPaths(ll m, ll n)
{
    ll path = 1;
    for (ll i = n; i < (m + n - 1); i++) {
        path *= i;
        // path /= (i - n + 1);
    }
    return path;
}

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        cout<<numberOfPaths(c-a+1,d-b+1)<<endl;
    }
}


// --------------------|
// Sachinam Srivastava |
//     26-05-2020      |
//---------------------|

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

#define ll long long

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        if(a != c and b != d)
            cout<<(d-b) + (c-a) + d*(c-a-1)<<endl;
        else
            cout<<1<<endl;
    }
}


// --------------------|
// Sachinam Srivastava |
//     26-05-2020      |
//---------------------|

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

#define ll unsigned long long

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
       if(a == c or b == d)
            cout<<"1\n";
        else
        {
            cout<<(d-b)*(c-a) + 1<<endl;
        }
    }
}


// --------------------|
// Sachinam Srivastava |
//     26-05-2020      |
//---------------------|

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

#define ll unsigned long long

ll numberOfPaths(ll m, ll n)
{
    ll path = 1;
    for (ll i = n; i < (m + n - 1); i++) {
        path *= i;
        path /= (i - n + 1);

    return path;
}

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        cout<<numberOfPaths(c-a+1,d-b+1)<<endl;
    }
}


// --------------------|
// Sachinam Srivastava |
//     26-05-2020      |
//---------------------|

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

#define ll unsigned long long

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
       if(a == c or b == d)
            cout<<"1\n";
        else
        {
            cout<<(d-b+1)*(c-a)<<endl;
        }
    }
}


// --------------------|
// Sachinam Srivastava |
//     26-05-2020      |
//---------------------|

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

#define ll unsigned long long

ll count_paths(ll m, ll n){
   if (m == 1 || n == 1)
      return 1;
   return count_paths(m - 1, n) + count_paths(m, n - 1);
}

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        cout<<count_paths(c-a+1,d-b+1)<<endl;
    //   if(a == c or b == d)
    //         cout<<"1\n";
    //     else
    //     {
    //         cout<<(d-b+1)*(c-a)<<endl;
    //     }
    }
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second

int p,q,f;

int path(int a, int b, int x, int y){

    if(x==p || y==q ){
        return 1;
    }

    else{
        if(a==x-1 && b==y-1){
            if(b==y-1)
            f=1;
            return 2;
        }
        else{
            if(x-a==1)
                if(f==0)
                return path(a,b,x-1,y-1) + y-b;
            else
                return path(a,b,x-1,y-1) + x-a;
            else{
                    if(f==0)
                return path(a,b,x-1,y-1) + y-b+1;
            else
                return path(a,b,x-1,y-1) + x-a+1;
            }

        }
    }
}
void solve(){
    ll a,b,x,y;
    cin>>a>>b>>x>>y;
    p=a, q=b;f=0;
    cout<<path(a,b,x,y)<<endl;
}

int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }

	return 0;
}


#include <iostream>
using namespace std;
int main(){
    int t;
    cin>> t;
    while(t--){
        long long int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        cout<<(x2-x1)*(y2-y1)+1<<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second

int p,q;

int path(int a, int b, int x, int y){

    if(x==p || y==q ){
        return 1;
    }

    else{
        if(a==x-1 && b==y-1)
            return 2;
        else{
            if(x-a==1)
                return path(a,b,x-1,y-1) + y-b;
            else
                return path(a,b,x-1,y-1) + y-b+1;

        }
    }
}
void solve(){
    ll a,b,x,y;
    cin>>a>>b>>x>>y;
    p=a, q=b;
    cout<<path(a,b,x,y)<<endl;
}

int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }

	return 0;
}