Chef Ada is building a new restaurant in the following way:
- First, $N$ points $X_1, X_2, \ldots, X_N$ are chosen on the $x$-axis.
- Then, $N$ columns (numbered $1$ through $N$) are made. For simplicity, the columns are represented as vertical segments; for each valid $i$, the height of the $i$-th segment is $H_i$.
- Ada assigns a column to each of the points $X_1, X_2, \ldots, X_N$ in an arbitrary way (each column must be assigned to exactly one point).
- Finally, Ada constructs the roof of the restaurant, represented by a polyline with $N$ vertices. Let's denote the column assigned to the $i$-th point by $P_i$. For each valid $i$, the $i$-th of these vertices is $(X_i, H_{P_i})$, i.e. the polyline joins the tops of the columns from left to right.
Ada wants the biggest restaurant. Help her choose the positions of the columns in such a way that the area below the roof is the biggest possible. Formally, she wants to maximise the area of the polygon whose perimeter is formed by the roof and the segments $(X_N, H_{P_N}) - (X_N, 0) - (X_1, 0) - (X_1, H_{P_1})$. Let $S$ be this maximum area; you should compute $2 \cdot S$ (it is guaranteed that $2 \cdot S$ is an integer).

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $X_i$ and $H_i$.

-----Output-----
For each test case, print a single line containing one integer $2 \cdot S$.

-----Constraints-----
- $1 \le T \le 3 \cdot 10^5$
- $2 \le N \le 10^5$
- $0 \le X_1 < X_2 < \ldots < X_N \le 2 \cdot 10^9$
- $1 \le H_i \le 10^9$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $10^6$

-----Example Input-----
1
5
1 1
2 2
3 3
4 4
5 5

-----Example Output-----
27

-----Explanation-----

Starter code:

Solutions:
# cook your dish here
t = int(input())
for _ in range(t):
 n = int(input())
 a = []
 b = []
 for i in range(n):
  x,y = list(map(int, input().split()))
  a.append(x)
  b.append(y)
 b.sort()
 xcor = []
 xcor.append(a[1]-a[0])
 xcor.append(a[n-1]-a[n-2])
 for i in range(1,n-1):
  xcor.append(a[i+1]-a[i-1])
 xcor.sort()
 ans = 0
 #print(xcor)
 #print(b)
 for i in range(n):
  ans = ans + xcor[i]*b[i]
 print(ans) 


t=int(input())
while(t):
 t-=1
 n=int(input())
 x = []
 h = []
 for i in range (n):
  xi,hi = [int(i) for i in input().split()]
  x.append(xi)
  h.append(hi)
 diff = [x[1]-x[0],x[n-1]-x[n-2]]
 for i in range (1,n-1):
  diff.append(x[i+1]-x[i-1])
 diff.sort()
 h.sort()
 ans = 0
 for i in range (n):
  ans+=h[i]*diff[i]
 print(ans)

# cook your dish here
for _ in range(int(input())):
 n = int(input())
 xloli=[]
 hloli=[]
 d1=[]
 d2=[]
 for i in range(n):
  (x,h)=(int(x) for x in input().split())
  xloli.append(x)
  hloli.append(h)
 for i in range(1,n):
  d1.append(xloli[i]-xloli[i-1])
 d2.append(d1[0])
 for i in range(n-2):
  d2.append(d1[i+1]+d1[i])
 d2.append(d1[-1])
 kaori=0
 hloli.sort()
 d2.sort()
 for i in range(n):
  kaori+=hloli[i]*d2[i]
 print(kaori)


t=int(input())
for i in range(t):
 n=int(input())
 xl=[]
 hl=[]
 for j in range(n):
  x,h=list(map(int,input().strip().split()))
  xl.append(x)
  hl.append(h)
 a=[0 for j in range(n)]
 a[0]=xl[1]-xl[0]
 for j in range(1,n-1):
  a[j]=xl[j+1]-xl[j-1]
 a[n-1]=xl[n-1]-xl[n-2]
 a.sort()
 hl.sort()
 sum=0
 for j in range(n):
  sum+=a[j]*hl[j]
 print(sum)


t = int(input())
for _ in range(t):
 n = int(input())
 a, b = [], []
 for _ in range(n):
  x, h = input().split()
  a.append(int(x))
  b.append(int(h))
 a = [y - x for x, y in zip(a, a[1:])]
 a = sorted(x + y for x, y in zip([0] + a, a + [0]))
 print(sum(x * y for x, y in zip(a, sorted(b))))

def find(X,H):
 if len(X) == 2:
  return (X[1]-X[0])*(sum(H))
 
 X = sorted(X)
 W = []
 for i in range(1,len(H)-1):
  W += [X[i+1]-X[i-1]]
 W += [X[1]-X[0]]
 W += [X[-1]-X[-2]]
 W = sorted(W)
 H = sorted(H)
 return sum([W[i]*H[i] for i in range(len(W))])

for _ in range(int(input())):
 N = int(input())
 X = []
 H = []
 for i in range(N):
  x,h = list(map(int,input().strip().split()))
  X += [x]
  H += [h]
 print(find(X,H))

'''a,b,c=map(int,input().split())
if a-b>>31 and a-c>>31:
    print(a)
elif b-c>>31 and b-a>>31:
    print(b)
else:
    print(c)'''



#*******************************************************************************    ************************


'''n=int(input())
c=0
a=[i for i in range(1,n+1)]
for i in range(n-1):
    for j in range(i,n):
     if a[i]^a[j]>n:
      c+=1
      print('('+str(i+1)+','+str(j+1)+')')
print(c)'''


#*******************************************************************************    ***************************


'''l=[0 for i in range(64)]
a=[str(i) for i in range(10)]+[chr(j) for j in range(65,91)]+[chr(k) for k in     range(97,123)]+['-','_']

for i in range(64):
    count=0
    for j in range(64):
     if i&j==i:
      count+=1
    l[i]=2*count-1
print(l)

for _ in range(int(input())):
    s=input()
    res=1
    for i in s:
     res*=l[a.index(i)]
    print(res%1000000007)'''



#*******************************************************************************    *****************************

for _ in range(int(input())):
 n=int(input())
 X=[0 for i in range(n)]
 H=[0 for i in range(n)]
 for i in range(n):
  x,h=list(map(int,input().split()))
  X[i]=x
  H[i]=h
 X1=[0 for i in range(n)]
 for i in range(n-2):
  X1[i]=X[i+2]-X[i]
 X1[n-2],X1[n-1]=X[1]-X[0],X[n-1]-X[n-2]
 X1.sort()
 H.sort()
 res=0
 for i in range(n):
  res+=X1[i]*H[i]
 print(res)


for _ in range(int(input())):
 n=int(input())
 x=[]
 p=[]
 for j in range(n):
  a,b=list(map(int,input().split()))
  x.append(a)
  p.append(b)
 differences=[]
 for u in range(n-1,1,-1):
  differences.append(x[u]-x[u-2])
 differences.append(x[-1]-x[-2])
 differences.append(x[1]-x[0])
 differences.sort()
 p.sort()
 answer=0
 while(len(differences)>0):
  answer=answer+(p.pop()*differences.pop())
 print(answer)


# cook your dish here
for i in range(int(input())):
 n=int(input())
 arr1=[]
 arr2=[]
 for i in range(n):
  l=input().split()
  arr1.append(int(l[0]))
  arr2.append(int(l[1]))
 arr1.append(arr1[-1])
 arr1.insert(0,arr1[0])
 arr2.sort()
 base=[]
 for i in range(1,n+1):
  base.append(arr1[i+1]-arr1[i-1])
 base.sort()
 ans=0
 for i in range(n):
  ans+=base[i]*arr2[i]
 print(ans)


# cook your dish here
# cook your dish here
t=int(input(''))
for k in range (t):
 n=int(input(''))
 li=[]
 li1=[]
 li2=[]
 for i in range (n):
  p,q=input().split()
  p=int(p)
  q=int(q)
  li.append(p)
  li1.append(q)
 r=li[1]-li[0]
 #print(r)
 li2.append(r)
 for i in range (1,n-1):
  p=li[i+1]-li[i-1]
  li2.append(p)
 li2.append(li[n-1]-li[n-2])
 li2.sort()
 li1.sort()
 ans=0
 for i in range (n):
  ans=ans+li1[i]*li2[i]
  #print(li2[i])
 print(ans)

for t in range(int(input())):
 x = []
 y = []
 z = []
 
 res = 0
 n = int(input(""))
 for i in range(n):
  temp1,temp2 = input("").split()
  x.append(int(temp1))
  y.append(int(temp2))
 
 z.insert(0,x[1] - x[0])
 z.insert(-1,x[-1] - x[-2])
 
 for i in range(1,n-1):
  z.insert(i,x[i+1] - x[i-1])
 
 y.sort(reverse = True)
 z.sort(reverse = True)
 for i in range(n):
  res = res + y[i] * z[i]
 
 print(res)

# cook your dish here
t = int(input())
for _ in range(t):
 n = int(input())
 a, b = [], []
 for _ in range(n):
  x, h = input().split()
  a.append(int(x))
  b.append(int(h))
 a = [y - x for x, y in zip(a, a[1:])]
 a = sorted(x + y for x, y in zip([0] + a, a + [0]))
 print(sum(x * y for x, y in zip(a, sorted(b))))

# cook your dish here
for _ in range(int(input())):
 n = int(input())
 x1, h1 = map(int, input().split())
 x2, h2 = map(int, input().split())
 l1 = [x2-x1]
 l2 = [h1, h2]
 for i in range(2, n):
  x, h = map(int, input().split())
  l1.append(x-x1)
  l2.append(h)
  x1 = x2
  x2 = x
 l1.append(x2-x1)
 l1.sort()
 l2.sort()
 a = 0
 for i in range(n):
  a += l1[i]*l2[i]
 print(a)

# cook your dish here
from sys import stdin

t = int(stdin.readline())

while t:
 n = int(stdin.readline())

 diff_prev = 0
 d, D = [], []
 h = [0]

 x_prev, h[0] = [int(x) for x in stdin.readline().split()]

 for i in range(n-1):
  x, ht = [int(x) for x in stdin.readline().split()]

  h.append(ht)
  d.append(x - x_prev)
  D.append(diff_prev + d[i])
  diff_prev = d[i]
  x_prev = x
 
 D.append(d[n-2])
 
 D.sort()
 h.sort()

 ans = 0
 for i in range(n):
  ans += D[i]*h[i]

 print(ans)

 t -= 1

# cook your dish here
from sys import stdin

t = int(stdin.readline())

while t:
 n = int(stdin.readline())

 diff_prev = 0
 d, D = [], []
 h = [0]

 x_prev, h[0] = [int(x) for x in stdin.readline().split()]

 for i in range(n-1):
  x, ht = [int(x) for x in stdin.readline().split()]

  h.append(ht)
  d.append(x - x_prev)
  D.append(diff_prev + d[i])
  diff_prev = d[i]
  x_prev = x
 
 D.append(d[n-2])
 
 D.sort()
 h.sort()

 ans = 0
 for i in range(n):
  ans += D[i]*h[i]

 print(ans)

 t -= 1

# cook your dish here

T = int(input())
t = 0
while t < T:
 t += 1
 N = int(input())
 h,x = list(), list()
 for i in range(N):
  a,b=list(map(int, input().split()))
  h.append(b)
  x.append(a)
  
 v=[]
 for i in range(N):
  v.append(x[min(i+1,N-1)]-x[max(i-1,0)])
 h.sort()
 v.sort()
 
 ans = 0
 for i in range(N):
  ans += h[i] * v[i]
 
 print(ans)
 


for t in range(int(input())):
 n=int(input())
 height=[]
 d=[]
 prev=0
 points=[]
 nex=0
 for i in range(n):
  x,h=[int(x) for x in input().split()]
  height.append(h)
  points.insert(i,x)
 for i in range(1,n):
  diff=points[i]-points[i-1]
  d.append(diff)
 points=[]
 for i in range(n-1):
  num=d[i]+prev
  prev=d[i]
  points.append(num)
 points.append(d[n-2])
 points.sort(reverse=True)
 height.sort(reverse=True)
 s=0
 for i in range(n):
  s+=(height[i]*points[i])
 print(s)
 
  
  
  


for _ in range(int(input())):
 n=int(input())
 a=[]
 g=[]
 h=[]
 I=list(map(int,input().split()))
 P=list(map(int,input().split()))
 a.append(I[0])
 a.append(P[0])
 h.append(I[1])
 h.append(P[1])
 g.append(a[1]-a[0])
 for i in range(2,n):
  L=list(map(int,input().split()))
  a.append(L[0])
  g.append(a[i]-a[i-2])
  h.append(L[1])
 g.append(a[-1]-a[-2])
 g.sort()
 h.sort()
 var=0
 for i in range(n):
  var+=h[i]*g[i]
 print(var)
  
  
 


t = int(input())
for _ in range(t):
 n = int(input())
 x, p = [], []
 for __ in range(n):
  line = list(map(int, input().split()))
  x.append(line[0])
  p.append(line[1])
 g = []
 for i in range(n-1):
  g.append(x[i+1] - x[i])
 bois = []
 bois.append(g[0])
 for k in range(n-2):
  bois.append(g[k+1] + g[k])
 bois.append(g[n-2])
 bois.sort()
 p.sort()
 ans = 0
 for i in range(n):
  ans += p[i] * bois[i]
 print(ans)
 
  


t = int(input())
for _ in range(t):
 n = int(input())
 x, p = [], []
 for __ in range(n):
  line = list(map(int, input().split()))
  x.append(line[0])
  p.append(line[1])
 g = []
 for i in range(n-1):
  g.append(x[i+1] - x[i])
 bois = []
 bois.append(g[0])
 for k in range(n-2):
  bois.append(g[k+1] + g[k])
 bois.append(g[n-2])
 bois.sort()
 p.sort()
 ans = 0
 for i in range(n):
  ans += p[i] * bois[i]
 print(ans)


# cook your dish here
T = int(input())
for _ in range(T):
 n = int(input())
 a, b = [], []
 for _ in range(n):
  x, h = input().split()
  a.append(int(x))
  b.append(int(h))
 a = [y - x for x, y in zip(a, a[1:])]
 a = sorted(x + y for x, y in zip([0] + a, a + [0]))
 print(sum(x * y for x, y in zip(a, sorted(b))))

for _ in range(int(input())):
 n = int(input())
 arr = []
 height = []
 d = []
 final = []
 for i in range(n):
  x,y = map(int,input().split())
  arr.append(x)
  height.append(y)
 for x in range(1,n):
  d.append(arr[x]-arr[x-1])
 final.append(d[0])
 for i in range(len(d)-1):
  final.append(d[i]+d[i+1])
 final.append(d[-1])
 height.sort()
 final.sort()
 ans = 0
 for x in range(n):
  ans+=(final[x]*height[x])
 print(ans)

for _ in range(int(input())):
 n = int(input())
 x_arr = []
 h_arr = []
 d = []
 D = []
 for i in range(n):
  x,y = map(int,input().split())
  x_arr.append(x)
  h_arr.append(y)
 for x in range(1,n):
  d.append(x_arr[x]-x_arr[x-1])
 D.append(d[0])
 for i in range(len(d)-1):
  D.append(d[i]+d[i+1])
 D.append(d[-1])
 h_arr.sort()
 D.sort()
 ans = 0
 for x in range(n):
  ans+=(D[x]*h_arr[x])
 print(ans)

t=int(input())
while t:
 dd=[]
 l=[]
 h=[]
 pr=0
 d=[]
 n=int(input())
 for i in range(n):
  x,hi=map(int,input().split())
  l.append(x)
  h.append(hi)
 l.sort()
 for i in range(1,n):
  dd.append(l[i]-l[i-1])
 d.append(dd[0])
 for i in range(1,n-1):
  d.append(dd[i]+dd[i-1])
 d.append(dd[-1])
 d.sort()
 h.sort()
 pr=0
 #print(d,h)
 for i in range(n):
  pr+=d[i]*h[i]
 print(pr)
 t-=1