#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
typedef vector<int> vi;
int main(){
int t;
cin>>t;
for(int testcase=0; testcase<t; testcase++){
int n, d, k; cin>>n>>d>>k;
vector<int> st (n+1, 0);
vector<int> end (n+1, 0);
for (int i = 0; i < k; i++)
{
int x, y;
cin>>x>>y;
++st[--x];
++end[--y]; //already sorted
}
int res=0, res2=0;
int idx=0; int endidx=0;
int window = 0;
for (int i = 0; i < d; i++)
{
if(st[i]>0) {window+=st[i]; }
}
int mx = window, mn =window;
for (int i = d; i < n; i++)
{
if(end[i-d]>0) {window-=end[i-d]; }
if(st[i]>0) {window+=st[i]; }
if(window>mx) {res = (i-d+1); mx = window;}
if(window<mn) {res2 = (i-d+1); mn = window;}
}
cout<<res+1<<" "<<res2+1<<endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+IAogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKI2RlZmluZSBlbmRsICJcbiIgCnR5cGVkZWYgbG9uZyBsb25nIGludCBsbDsKdHlwZWRlZiB2ZWN0b3I8aW50PiB2aTsKCgppbnQgbWFpbigpewogICAgaW50IHQ7CiAgICBjaW4+PnQ7CiAgICAKICAgIGZvcihpbnQgdGVzdGNhc2U9MDsgdGVzdGNhc2U8dDsgdGVzdGNhc2UrKyl7CiAgICAgICAgaW50IG4sIGQsIGs7IGNpbj4+bj4+ZD4+azsKCiAgICAgICAgdmVjdG9yPGludD4gc3QgKG4rMSwgMCk7CiAgICAgICAgdmVjdG9yPGludD4gZW5kIChuKzEsIDApOwoKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IGs7IGkrKykKICAgICAgICB7ICAgCiAgICAgICAgICAgIGludCB4LCB5OwogICAgICAgICAgICBjaW4+Png+Pnk7CiAgICAgICAgICAgICsrc3RbLS14XTsKICAgICAgICAgICAgKytlbmRbLS15XTsJLy9hbHJlYWR5IHNvcnRlZAogICAgICAgIH0KCiAgICAgICAgaW50IHJlcz0wLCByZXMyPTA7CgogICAgICAgIGludCBpZHg9MDsgaW50IGVuZGlkeD0wOwogICAgICAgIGludCB3aW5kb3cgPSAwOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgZDsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgaWYoc3RbaV0+MCkge3dpbmRvdys9c3RbaV07IH0KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgaW50IG14ID0gd2luZG93LCBtbiA9d2luZG93OwogICAgICAgIGZvciAoaW50IGkgPSBkOyBpIDwgbjsgaSsrKQogICAgICAgIHsKICAgICAgICAgICBpZihlbmRbaS1kXT4wKSB7d2luZG93LT1lbmRbaS1kXTsgfQoKICAgICAgICAgICAgaWYoc3RbaV0+MCkge3dpbmRvdys9c3RbaV07IH0KCiAgICAgICAgICAgIGlmKHdpbmRvdz5teCkge3JlcyA9IChpLWQrMSk7IG14ID0gd2luZG93O30KICAgICAgICAgICAgaWYod2luZG93PG1uKSB7cmVzMiA9IChpLWQrMSk7IG1uID0gd2luZG93O30KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgY291dDw8cmVzKzE8PCIgIjw8cmVzMisxPDxlbmRsOwogICAgfQoKICAgIHJldHVybiAwOwp9