{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003ccenter\u003e\u003cH1\u003eA\u003c/H1\u003e\u003c/center\u003e\u003cp\u003eTheofanis really likes sequences of positive integers, thus his teacher (Yeltsa Kcir) gave him a problem about a sequence that consists of only special numbers.\u003c/p\u003e\n\u003cp\u003eLet\u0027s call a positive number \u003cspan class\u003d\"tex-font-style-it\"\u003especial\u003c/span\u003e if it can be written as a sum of \u003cspan class\u003d\"tex-font-style-bf\"\u003edifferent\u003c/span\u003e non-negative powers of $$$n$$$. For example, for $$$n \u003d 4$$$ number $$$17$$$ is special, because it can be written as $$$4^0 + 4^2 \u003d 1 + 16 \u003d 17$$$, but $$$9$$$ is not.\u003c/p\u003e\n\u003cp\u003eTheofanis asks you to help him find the $$$k$$$-th special number if they are sorted in increasing order. Since this number may be too large, output it modulo $$$10^9+7$$$.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u0026nbsp;— the number of test cases.\u003c/p\u003e\n\u003cp\u003eThe first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\le n \\le 10^9$$$; $$$1 \\le k \\le 10^9$$$).\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each test case, print one integer\u0026nbsp;— the $$$k$$$-th special number in increasing order modulo $$$10^9+7$$$.\u003c/p\u003e"}},{"title":"Example","value":{"format":"HTML","content":"\u003cdiv class\u003d\"sample-test\"\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e3\n3 4\n2 12\n105 564\n\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e9\n12\n3595374\n\u003c/pre\u003e\n \u003c/div\u003e\n\u003c/div\u003e"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eFor $$$n \u003d 3$$$ the sequence is $$$[1,3,4,9...]$$$\u003c/p\u003e"}}]}