Gargle

Time limit1sMemory limit128 MB

Summary
Print base-7 digits of N/D from position B through E after the radix point, with leading zeros preserved.
Level

Medium4 of 10

Topics
Math, Simulation, Implementation
Solved
No attempts yet

Problem

Google once put up the following billboard along Highway 101, which runs through the heart of Silicon Valley:

"{first 10-digit prime found in consecutive digits of ee}.com"

Deeply impressed by this recruiting stunt, a mouthwash company named Gargle decided to hire people with the following problem:

"{the digits of a certain rational number written in base 7, from the BB-th digit through the EE-th digit after the radix point}.com"

For example, 15\frac{1}{5} (in base 10) written in base 7 is 0.12541…(7)0.12541\ldots_{(7)}, 334\frac{33}{4} is 11.15151…(7)11.15151\ldots_{(7)}, and 649\frac{6}{49} is 0.06000…(7)0.06000\ldots_{(7)}.

Given a rational number ND\frac{N}{D}, write a program that prints its base-7 digits from the BB-th digit through the EE-th digit after the radix point.

Input

The first line contains the number of test cases TT.

Each test case is given on a single line as four base-10 integers NN, DD, BB, and EE separated by spaces. NN and DD are the numerator and denominator of the rational number, with 0≤N≤5,0000 \le N \le 5{,}000 and 1≤D≤5,0001 \le D \le 5{,}000. BB and EE give the range of digit positions to output, with 0≤B,E≤2500 \le B, E \le 250 and 0≤E−B≤200 \le E - B \le 20.

The 00-th digit after the radix point is the digit immediately to the right of the point.

Output

For each test case, print one line in the following format:

Problem set k: N / D, base 7 digits B through E: result

Here kk is the test case number (starting from 1), resultresult is the computed digit string, and the other values NN, DD, BB, EE are those given in the input. Leading zeros in resultresult are printed as-is.

Examples1

  1. Example 1

    Input
    4
    1 5 0 0
    6 49 1 3
    33 4 2 7
    511 977 122 126
    
    Expected output
    Problem set 1: 1 / 5, base 7 digits 0 through 0: 1
    Problem set 2: 6 / 49, base 7 digits 1 through 3: 600
    Problem set 3: 33 / 4, base 7 digits 2 through 7: 151515
    Problem set 4: 511 / 977, base 7 digits 122 through 126: 12425