#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define sort sort(v.begin(),v.end());
//freopen("sets.in", "r", stdin);
using namespace std;
long long mod=1e9+7;
long long power(long long n, long long m)
{
if (!m)return 1;
if (m==1)return n%mod;
long long lol=power(n,m/2);
return (m&1?((((n%mod)*(lol%mod))%mod)*(lol%mod))%mod:((lol%mod)*(lol%mod))%mod);
}
long long ncr(long long n, long long m)
{
if(m==0)return 1;
return ((((n%mod)*(ncr(n-1,m-1)%mod))%mod)/m)%mod;
}
long long npr(long long n, long long r) {
if (r > n)
return 0;
long long p = 1, i = n - r + 1;
while (i <= n)
p *= i++;
return p;
}
bool prime(long long x)
{
if (x<=1)return 0;
for (int i=2; i<=sqrt(x); i++)
if (!(x%i))
return 0;
return 1;
}
long long fact(long long a)
{
if (!a)return 1; return (a == 1 ? 1 : fact(a - 1) * a);
}
int main()
{
speed
//coming..soon
int t=1;
cin>>t;
while(t--){
long long n, p, l, t;
cin >> n >> p >> l >> t;
long long total =(n+6)/7 ;
long long st = 0, ed = n;
while (st<ed)
{
long long mi = (st + ed + 1) / 2;
long long sum = (n - mi) * l + t * min(total, (n - mi) * 2ll);
if (sum >= p) st = mi;
else ed = mi - 1;
}
cout <<st<< "\n";
}
return 0;
}
1519A - Red and Blue Beans | 466A - Cheap Travel |
659E - New Reform | 1385B - Restore the Permutation by Merger |
706A - Beru-taxi | 686A - Free Ice Cream |
1358D - The Best Vacation | 1620B - Triangles on a Rectangle |
999C - Alphabetic Removals | 1634C - OKEA |
1368C - Even Picture | 1505F - Math |
1473A - Replacing Elements | 959A - Mahmoud and Ehab and the even-odd game |
78B - Easter Eggs | 1455B - Jumps |
1225C - p-binary | 1525D - Armchairs |
1257A - Two Rival Students | 1415A - Prison Break |
1271A - Suits | 259B - Little Elephant and Magic Square |
1389A - LCM Problem | 778A - String Game |
1382A - Common Subsequence | 1512D - Corrupted Array |
667B - Coat of Anticubism | 284B - Cows and Poker Game |
1666D - Deletive Editing | 1433D - Districts Connection |