#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int t,n,m;
cin>>t;
while(t--){
cin>>n>>m;
int mx=-1e9,mi=1e9;
for(int i=0;i<=n;i++){
int z=m-3*n+i;
int y=n-z-i;
if(z<0||y<0)continue;
if(i*2+3*y+4*z==m){
mx=max(z,mx);
mi=min(z,mi);
}
}
if(mi==1e9&&mx==-1e9)cout<<0<<" "<<0<<endl;
else cout<<mi<<" "<<mx<<endl;
}
return 0;
}
//z-x=m-3n不定方程