Under construction

Still being built. Things may change

I want to eat chicken

Time limit1sMemory limit256 MB

Summary
Each person buys as many chickens as his money allows; compute how many more Sangeon eats than Dooyoung given coupon rules.
Level

Medium4 of 10

Topics
Math, Simulation, Implementation
Solved
No attempts yet

Problem

Building 301 at Seoul National University hides a fried chicken shop called Nupchicken. Every time you order a chicken there, the shop hands you CC coupons, and FF coupons buy one free chicken.

Dooyoung is not a regular, so a chicken he orders with coupons comes with no coupons at all. Sangeon is a regular, and the owner gives him coupons even for a chicken ordered with coupons.

Sangeon and Dooyoung each have MM won, and one chicken costs PP won. Each of them orders as many chickens as his money allows and takes a free chicken every time he has collected FF coupons. Find how many more chickens Sangeon eats than Dooyoung.

Input

The first line contains the number of test cases TT (1≤T≤20,0001 \le T \le 20{,}000). The TT test cases follow.

Each test case is one line with four integers: the price of one chicken PP (1≤P≤50,0001 \le P \le 50{,}000), the money available for chicken MM (1≤M≤1,000,0001 \le M \le 1{,}000{,}000), the number of coupons needed for one free chicken FF (2≤F≤1,0002 \le F \le 1{,}000), and the number of coupons given for one ordered chicken CC (1≤C<F1 \le C < F), in that order.

Output

For each test case, print on its own line how many more chickens Sangeon eats than Dooyoung.

Examples7

  1. Example 1

    Input
    2
    10000 50000 5 1
    10000 250000 5 1
    
    Expected output
    0
    1
  2. Example 2

    Input
    1
    50000 49999 2 1
    
    Expected output
    0
  3. Example 3

    Input
    1
    1 1 2 1
    
    Expected output
    0
  4. Example 4

    Input
    1
    100 500 5 1
    
    Expected output
    0
  5. Example 5

    Input
    1
    1 10 2 1
    
    Expected output
    4
  6. Example 6

    Input
    1
    50000 1000000 2 1
    
    Expected output
    9
  7. Example 7

    Input
    4
    7 100 3 2
    1000 1000000 1000 999
    25 25 4 3
    13 999999 2 1
    
    Expected output
    17
    997002
    0
    38461