P20543 [HackerEarth] Gazu is a bright kid fascinated by the concept of number line. He made a long number line (0 to infinity) in his backyard and decided to play “Jump on cherry”. He stood at zero of the nu
普及
题目描述

Gazu is a bright kid fascinated by the concept of number line. He made a long number line (0 to infinity) in his backyard and decided to play “Jump on cherry”. He stood at zero of the number line and jumped X distance ahead. After he jumps he throws a red cherry Y distance ahead. Again he jumps X distance ahead and then he throws a new red cherry 2Y distance ahead, again he jumps X ahead and throws a new red cherry 3Y distance ahead. He repeats these steps until he jumps on a red cherry. Now he asks you to calculate the time after which he will jump on a cherry.
Assuming: he jumps after every 1 second, time elapsed in throwing a cherry is zero second, there was no cherry on the ground before the game and Gazu have infinite supply of cherries.

INPUT
first line contains number of testcases 0<t<100, next t lines contains two space separated integers corresponding to X and Y. 2<X,Y<2000

OUTPUT
t lines, each containing the time (in seconds) after Gazu will jump on a cherry for each testcase.

SAMPLE INPUT
1
4 2

SAMPLE OUTPUT
3

Explanation

X=4 and Y=2
See picture above in the problem statement.
Total number of jumps required to jump on a cherry x time elapsed in single jump= Total time
3 jumps x 1 second= 3 seconds

输入格式

见题面

输出格式

见题面

样例输入
50 4 2 16 76 56 65 70 10 21 84 59 37 100 80 48 31 69 41 88 72 56 12 69 36 72 54 48 76 4 12 28 41 90 27 66 97 80 54 87 53 97 60 9 43 45 50 63 69 27 34 39 89 78 53 93 54 33 39 66 83 72 40 90 7 76 20 90 40 14 34 100 84 79 78 20 5 14 53 7 68 26 58 66 77 33 82 29 48 10 43 16 59 11 77 70 74 14 13 33 43
样例输出
947 1945 373 1845 1883 954 278 90 1907 1907 307 1856 945 955 1947 1896 1898 1825 1883 1897 1919 1935 1947 1927 1895 1891 1879 1915 478 963 1932 1937 386 1988 962 645 937 1915 974 1883 1926 1960 1857 646 1889 1843 626 1937 1868 1897 604 388 942 1877 1911 1915 1875 1851 213 1861 992 959 1957 1901 627 1887 1938 267 1874 1913 1883 1944 173 1869 1953 1888 1947 1883 385 1969 1920 1927 1932 1942 923 640 1863 664 943 165 937 1927 1873 933 1889 627 1959 1892 1852 41