/**
hdu 4335 Party All the Time
数学计算题,枚举每段区间,
在每个区间上构造一元三次函数,求最小值。
注意n == 1时直接输出0
据说这个三分可以了,又据说可以O(1)的找到最优解的根。
*/
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define N 50005
#define INF 1e10
#define EPS 1e-8
double x[N],w[N],sw[N],swx[N],swx2[N],swx3[N];
int n;
double a,b,c,d,aa,bb,cc,x1;
double f(double xx)
{
return a * xx * xx * xx + b * xx * xx + c * xx + d;
}
int main()
{
int t,cas = 0,i;
scanf("%d",&t);
double res,tmp;
while(t--)
{
scanf("%d",&n);
for(i = 1; i <= n; ++i)
{
scanf("%lf%lf",x+i,w+i);