#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lld;
#define pll pair<ll,ll>
#define vll vector<ll>
#define ln "\n"
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define be begin
#define ub upper_bound
#define lb lower_bound
#define bi binary_search
#define sll set <ll>
#define msll multiset <ll>
#define vpll vector <pair<ll,ll>>
#define mll map <ll,ll>
#define all(v) v.begin(),v.end()
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define i1(x) cin>>x
#define i2(x1,x2) cin>>x1>>x2
#define i3(x1,x2,x3) cin>>x1>>x2>>x3
#define i4(x1,x2,x3,x4) cin>>x1>>x2>>x3>>x4
#define o1(x) cout<<x<<ln
#define o2(x1,x2) cout<<x1<<" "<<x2<<ln
#define o3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<ln
#define o4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<ln
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define rrep(i,s,e) for(ll i=s-1;i>=e;i--)
#define geta(a,n) for(ll i=0;i<n;i++)cin>>a[i];
const ll mod = 998244353;
const ll infinity = 1e18;
void solve()
{
ll l,r;
i2(l,r);
ll mx=1;
ll sz=1;
while(1)
{
ll val=l*pow(2,mx);
if(val>r)
break;
sz++;
mx++;
}
if(sz==1)
{
o2(1,r-l+1);
return;
}
ll size=sz;
mx--;
ll ratio=pow(2,mx);
ll left=l,right=r;
ll we=-1;
ll ct=0;
//o1(ratio);
while(left<=right)
{
// ct++;
// if(ct>10)
// break;
ll mid=(left+right)/2;
ll vv=r/mid;
//o4(left,right,mid,vv);
if(vv<ratio)
{
right=mid-1;
}
else
{
we=mid;
left=mid+1;
}
}
ratio=(ratio*3)/2;
ll wee=-1;
left=l,right=r;
while(left<=right)
{
// ct++;
// if(ct>20)
// break;
ll mid=(left+right)/2;
//o3(left,right,mid);
ll vv=r/mid;
if(vv<ratio)
{
right=mid-1;
}
else
{
wee=mid;
left=mid+1;
}
}
//o2(we,wee);
ll ans;
if(wee==-1)
{
ans=(we-l+1)%mod;
o2(size,ans);
return;
}
ll ft=wee-l+1;
ll st=we-wee;
ans=(ft*(size))%mod;
ans=(ans+st)%mod;
o2(size,ans);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t = 1;
cin >> t;
srand(time(0));
for (ll i = 1; i <= t; i++)
{
//cout << "Case #" << i << ": ";
solve();
}
return 0;
}
2144. Minimum Cost of Buying Candies With Discount | Non empty subsets |
1630A - And Matching | 1630B - Range and Partition |
1630C - Paint the Middle | 1630D - Flipping Range |
1328A - Divisibility Problem | 339A - Helpful Maths |
4A - Watermelon | 476A - Dreamoon and Stairs |
1409A - Yet Another Two Integers Problem | 977A - Wrong Subtraction |
263A - Beautiful Matrix | 180C - Letter |
151A - Soft Drinking | 1352A - Sum of Round Numbers |
281A - Word Capitalization | 1646A - Square Counting |
266A - Stones on the Table | 61A - Ultra-Fast Mathematician |
148A - Insomnia cure | 1650A - Deletions of Two Adjacent Letters |
1512A - Spy Detected | 282A - Bit++ |
69A - Young Physicist | 1651A - Playoff |
734A - Anton and Danik | 1300B - Assigning to Classes |
1647A - Madoka and Math Dad | 710A - King Moves |