#include<bits/stdc++.h>
#define ll long long
#define i28 __int128
#define pii pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
int n;
struct Node{ll a,b;}c[3030];
bool operator<(Node a,Node b){
return ((i28)a.a*(i28)b.b<(i28)a.b*(i28)b.a);
}
ll sum[3030],sum1[3030];
vector<pii>vec,v1,v2;
void solve(){
ll sa=0,sb=0;
for(int i=1;i<=n;++i)scanf("%lld%lld",&c[i].a,&c[i].b),sa+=c[i].a,sb+=c[i].b;
sort(c+1,c+n+1);i28 ans=0;
vec.clear();vec.pb(mp(0,0));
for(int i=1;i<=n;++i){
for(auto v:vec)v2.pb(mp(v.fi+c[i].a,v.se+c[i].b));
vec.clear();
int p=0,q=0;
while(p<v1.size()&&q<v2.size()){
if(v1[p]<v2[q])vec.pb(v1[p++]);
else vec.pb(v2[q++]);
}
while(p<v1.size())vec.pb(v1[p++]);
while(q<v2.size())vec.pb(v2[q++]);
ll mx=-1e18;
v1.clear();
for(auto v:vec){
if(v.se<=mx)continue;
mx=v.se,v1.pb(v);
}
while(vec.size()>3000)vec.pop_back();
vec=v1;
}
for(auto v:vec)ans=max(ans,(i28)(s-v.fi)*(i28)v.se);
stack<char>stk;while(stk.size())stk.pop();
while(ans)stk.push((char)(ans%(i28)(10)+'0')),ans/=(i28)(10);
while(stk.size())putchar(stk.top()),stk.pop();
puts("");
}
int main(){
int t;ll ta,tb;
cin>>t>>n>>ta>>tb;
while(t--)solve();
return 0;
}