{"raw_statement":[{"iden":"problem statement","content":"You are given positive integers $A$ and $B$.\nFind the minimum value of $X+Y$ for non-negative integers $X$ and $Y$ such that $B+Y$ is a multiple of $A+X$.\nYou have $T$ test cases to solve."},{"iden":"constraints","content":"*   $1 \\leq T \\leq 100$\n*   $1 \\leq A,\\ B \\leq 10^9$\n*   All values in the input are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$T$\n$\\mathrm{case}_{1}$\n$\\mathrm{case}_{2}$\n$\\vdots$\n$\\mathrm{case}_{T}$\n\nEach case is in the following format:\n\n$A$ $B$"},{"iden":"sample input 1","content":"5\n11 23\n8 16\n4394 993298361\n95392025 569922442\n8399283 10293"},{"iden":"sample output 1","content":"2\n0\n65\n2429708\n8388990\n\nFor the first test case, if we let $X=1$ and $Y=1$, then $B+Y=24$ will be a multiple of $A+X=12$. Here, we have $X+Y=2$, and there is no way to make $X+Y$ smaller, so the answer is $2$.\nFor the second test case, if we let $X=0$ and $Y=0$, then $B+Y=16$ will be a multiple of $A+X=8$."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}