#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> P;
vector<P> q,p;
int n;
bool check(long long x,long long y) {
multiset<P> st1,st2;
for(int i=0;i<q.size();i++) {
st1.insert(q[i]);
st2.insert(p[i]);
}
for(int i=n;i>=1;i--) {
int tx=st1.rbegin()->first;
int ty=st1.rbegin()->second;
if(tx==x) {
y-=ty;
st1.erase(st1.find({tx,ty}));
st2.erase(st2.find({ty,tx}));
continue;
}
tx=st2.rbegin()->second;
ty=st2.rbegin()->first;
if(ty==y) {
x-=tx;
st1.erase(st1.find({tx,ty}));
st2.erase(st2.find({ty,tx}));
continue;
}
return false;
}
return true;
}
int main()
{
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
cin>>n;
long long sum=0;
long long mx=0,my=0;
q.clear();
p.clear();
for(int i=1;i<=n;i++)
{
long long x,y;
cin>>x>>y;
q.push_back(make_pair(x,y));
p.push_back(make_pair(y,x));
sum+=1ll*x*y;
mx = max(x, mx);
my = max(y, my);
}
long long My=-1,Mx=-1;
int flag=0;
if(sum%mx==0)
{
My=sum/mx;
flag++;
}
if(sum%my==0)
{
Mx = sum/my;
flag++;
}
if(Mx==mx&&My==my)
{
cout<<1<<endl;
cout<<mx<<" "<<my<<endl;
continue;
}else if(flag==1)
{
cout<<flag<<endl;
if(My!=-1)
{
cout<<mx<<" "<<My<<endl;
}
if(Mx!=-1)
{
cout<<Mx<<" "<<my<<endl;
}
}else
{
if(!check(mx,My))
{
My=-1;
flag--;
}
if(!check(Mx,my))
{
Mx=-1;
flag--;
}
cout<<flag<<endl;
if(My!=-1)
{
cout<<mx<<" "<<My<<endl;
}
if(Mx!=-1)
{
cout<<Mx<<" "<<my<<endl;
}
}
}
return 0;
}
切割典中典
最新推荐文章于 2024-07-19 15:39:46 发布