#include <iostream>
#include <cmath>using namespace std;int _gcd(int x,int y){
return y==0?x:_gcd(y,x%y);}void main()
{ int T,x0,y0,n; cin>>T; while(T--) { cin>>x0>>y0; cin>>n; int x1=0,y1=0; for(int i=0;i<n;i++) { int x2,y2; cin>>x2>>y2; x1+=x2; y1+=y2; }x1-=x0*n; y1-=y0*n;if(x1==0&&y1==0)
cout<<0<<' '<<0<<endl; else if(x1==0&&y1!=0) cout<<0<<' '<<y1<<endl; else if(x1!=0&&y1==0) cout<<x1<<' '<<0<<endl; else if(x1!=0&&y1!=0) { int gcd=_gcd(abs(x1),abs(y1)); cout<<x1/gcd<<' '<<y1/gcd<<endl; } }}