You have n rectangles, the i-th rectangle has height and width.
You are asked q queries of the form hs ws hb wbℎ ℎ.
For each query output, the total area of rectangles you own that can fit a rectangle of height hsℎ and width ws while also fitting in a rectangle of height hbℎ and width wb. In other words, print ∑hi⋅wi∑ℎ⋅ for i such that hs<hi<hb and ws<wi<wb.
Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.
Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
Input
The first line of the input contains an integer t (1≤t≤100) — the number of test cases.
The first line of each test case two integers n,q (1≤n≤105; 1≤q≤105) — the number of rectangles you own and the number of queries.
Then n lines follow, each containing two integers hi,wiℎ(1≤hi,wi≤10001≤ℎ) — the height and width of the i-th rectangle.
Then q lines follow, each containing four integers hs,ws,hb,wbℎ(1≤hs<hb, ws<wb≤1000) — the description of each query.
The sum of q over all test cases does not exceed 105105, and the sum of n over all test cases does not exceed 105105.
Output
For each test case, output q lines, the i-th line containing the answer to the i-th query.
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define endl '\n'
using namespace std;
const int N=1e5+7;
int n,q,a[1005][1005];
void solve()
{
memset(a,0,sizeof(a));
cin>>n>>q;
for(int i=1;i<=n;i++)
{
int x,y;
cin>>x>>y;
a[x][y]+=x*y;
}
for(int i=1;i<=1000;i++)
{
for(int j=1;j<=1000;j++)
{
a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
}
}
while(q--)
{
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
x1++;x2--;y1++;y2--;
cout<<a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1]<<endl;
}
}
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}