Number Transform

All submissions for this problem are available.
Problem Description
In the world of Mathematics, there are ordinary numbers and there are special numbers. The special numbers are Transformers. The transformers are of two types  Autobots and Decepticons. Autobots have the task of saving the numberkind from the evil intentions of Decepticons.
A number C is said to be equivalent to another number D if C%k = D%k, where k is a given parameter.
The Transformers are called so because of their special ability to transform to something else. Now, given a value Q, a transformer N wishes to transform to another value P such that P is equivalent to Q.
However, like all mortal beings, they too have restrictions, they can only take some particular transformations.
The following transformations are allowed
N > N + a
N > N  b
N > N * c
N > N % d
You have to report minimum number of steps to transform to such a value P (which is equivalent to Q) using the above transformations, or print 1 if it is impossible to do so.
Input Format
First line contains T, the number of test cases. T lines follow, each containing 7 space separated integers, N, a, b, c, d, k, q.
Output Format
The output consists of T lines. Each line contains the output of the corresponding test case, i.e., the minimum number of transformations required or 1, if transformation is not possible.
Sample Input
2
10 3 2 5 5 4 12
5 1 2 3 4 9 14
Sample Output
1
0
Constraints
1 <= T <= 1000
1 <= N,a,b,c,d,k,Q <= 1000
Explanation
For test case 1:
1. Take 10 modulo 5 > 0 which equals 12 modulo 4
For test case 2: No operations requires as 5 modulo 9 = 14 modulo 9
Note:
modulo operation is defined here. It is commonly implemented as %
operator in many programming languages.
All test cases are generated randomly.
Author:  iopc_admin 
Tags  iopc_admin 
Date Added:  2022014 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP 4.9.2, GO, JAVA 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions