EASYMATH - EASY MATH

You will be given 4 numbers: n m a d.

Find count of numbers between n and m (inclusive) not divisible by (a) or (a+d) or (a+2d) or (a+3d) or (a+4d).

Input

First line has number t - number of test cases.

Each test case has 4 numbers n m a d.

Output

Single line having single number giving the count.

Constraints

1 ≤ n ≤ m ≤ 232

1 ≤ a ≤ 232

1 ≤ d ≤ 232

2 ≤ t ≤ 100

Example

Input:
3
1 10 2 2
20 100 3 3
100 1000 4 5

Output:
5
54
543

Also try the challenge version at EASYMATC


Added by:Devil D
Date:2012-04-17
Time limit:0.100s-1s
Source limit:20000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own

hide comments
2018-10-16 19:58:30
very nice problem :)
2018-09-10 19:09:01
solvable using inclusion-exclusion principle take care of implementation
2017-09-01 00:29:27
tle by iteration..
2016-02-01 12:05:01 kejriwal
easy math :)
2015-10-29 06:02:54
got TLE :-)
2015-10-27 13:07:51 Sonu Sharma
Take special care of :n & m (inclusive) <<<<<not>>>>> divisible by
2015-09-27 20:03:42 arpita
anyone had its correct ans? plz comment ur id,
2015-09-27 09:37:23 varun yadav
my solution is showing WA,, what should i do ??? link ----> http://ideone.com/yAVncM
2015-01-07 17:52:44 Abhinav
getting WA at 9th case any tricky case ?
2014-11-18 13:39:31 ayushi agarwal
why unsigned int doesn't work and long long int work in c++
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.