Generating Numbers from Numbers

All submissions for this problem are available.
Problem description.
Generating numbers from another number using the 4 basic arithmetic operations addition(+), subtract() multiply(*) divide(/) is quite a game with a few simple rules.
 Only perform integer division i.e. 8 /3 results in 2.6667 but only 2 should be taken into account.
 Operations having same results should be taken as different contexts e.g. 8 * 3 is same as 3 * 8 but should be taken as 2 separate methods of generating numbers.
 Take (anynumber / 0) equal to 0.
 Take negative numbers as positive.
 Digits range from 0  9.
 Only digit comparison should be done.(Hint)
 General Rule For generating numbers
 take a digit(start from left to right) from the number and perform the 4 operations with the next digit(start again from left to right, same digit position should be skipped), save these 4 results and check if these results equal any digit from the destination, again perform the 4 operations onto these 4 results with the next digit, until you reach the end.
3 digit number Example
source 386, destination 214
 Start from the first digit (i.e.start from left to right) of the source and perform the 4 operations with the second digit(i.e. start again from left to right, same digit position should be skippped). check if these results equal any digit from the destination, next again perform the 4 operations onto these 4 results with the third digit of the source.
e.g.
Step 1.1
3 + 8(=11), 3  8(=5) , 3 * 8(=24), 3 / 8(=0)
11, 5, 24, 0 are not present in the destination number.
Step 1.2
11 + 6, 11  6, 11 * 6, 11 / 6
5 + 6, 5  6, 5 * 6, 5 / 6
24 + 6, 24  6, 24 * 6, 24 / 6
0 + 6, 0  6, 0 * 6, 0 / 6
The operation 11 / 6 results in 1 which is present in the destination number, so now 1 can be generated in 1 way.
The operation 5  6 results in 1 which is present in the destination number, so now 1 can be generated in 2 ways.
The operation 24 / 6 results in 4 which is present in the destination number, so now 4 can be generated in 1 ways.
etc.
The Next step is to take second digit of the source number and perform the 4 operations with the first digit.
Step 2.1
8 + 3(=11), 8  3(=5) , 8 * 3(=24), 8 / 3(=2)
The operation 8 / 3 results in 2 which is present in the destination number, so now 2 can be generated in 1 way.
Step 2.2
11 + 6, 11  6, 11 * 6, 11 / 6
5 + 6, 5  6, 5 * 6, 5 / 6
24 + 6, 24  6, 24 * 6, 24 / 6
2 + 6, 2  6, 2 * 6, 2 / 6
The operation 11 / 6 results in 1 which is present in the destination number, so now 1 can be generated in 3 way.
The operation 5  6 results in 1 which is present in the destination number, so now 1 can be generated in 4 ways.
The operation 24 / 6 results in 4 which is present in the destination number, so now 4 can be generated in 2 ways.
The operation 2  6 results in 4 which is present in the destination number, so now 4 can be generated in 3 ways.
etc.
Following is an example showing how digits from the destination can be made from the source string.
e.g.
386(source) > 214(destination) can produce 2(first digit of the resultant number) in following ways
8 / 3
6 / 3
(6 * 3) / 8
1(second digit of the resultant number) in following ways
(3 + 8) / 6
(3  8)  6
(8 + 3) / 6
(8  3)  6
(6 + 3) / 8
(6 + 3)  8
4(third digit of the resultant number) in following ways
(3 * 8) / 6
(8 * 3) / 6
(8 / 3)  6
Input
 The first line of the input contains the number of test cases T .
 Each of the next T lines contains two positive integers x and y separated by a spacethe first number being the source and the second number being the destination.
Output
 For each test case, display the number of times the destination number can be formed from the source number.
Constraints
 1 ≤ T ≤ 10
Example
Input: 1 386 214 Output: 3
Author:  himanshu200 
Tags  himanshu200 
Date Added:  15032013 
Time Limit:  1.71429 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 