{"trustable":true,"prependHtml":"\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 async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eAlice and Bob are going to Tenbaba for an interview. There are totally N candidates(including Alice and Bob) applying for this job. The recruitment process of Tenbaba is strict. So all of them need to have an interview with the department manager. N candidates will get a unique integer from $1$ to $N$ with equal probability. And they will go to interview with the manager according to the number they get. The candidate with number 1 will be interviewed firstly, the candidate with number 2 will be interviewed secondly and so on.\u003cbr\u003e\u003cbr\u003eWhat\u0027s more, HR(the staff to arrange the interview for you) will randomly choose a nonnegative integer $K$ in range $[0..N]$ with equal probability. The candidates whose numbers are not greater than $K$ will be interviewed in order of their numbers on the first day. Remaining candidates will be interviewed in order of their numbers on the second day. Candidates don\u0027t know $K$. But each one will knows on which day he or she will be interviewed.\u003cbr\u003e\u003cbr\u003eSadly, Alice forgot her number. The only thing she remember is that she will be interviewed on the second day. Alice also knows on which day Bob will be interviewed. But she doesn\u0027t know the exact number Bob has. Assume that Alice would be the $Y$-th$(1\\leq Y \\leq N - K)$ candidate to interview with the manager on the second day. Please help Alice to calculate the expectation of $Y$ because Alice doesn\u0027t want to go out too early.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line is the number of test cases. It\u0027s guaranteed that the test cases is not greater than $10^5$.\u003cbr\u003e\u003cbr\u003eEach test case contains two integers $N$ and $D$ $(2 \\leq N \\leq 10^9, D \u003d \\ 1 \\ or \\ 2$). $D \u003d 1$ means Bob will be interviewed on the first day and $D \u003d 2$ means Bob will be interviewed on the second day.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"Each test case contains one line with one integer. Let\u0026amp;#161;ˉs assume the possibility be equal to the irreducible fraction $P / Q$. Print the value of $P\\cdot Q^{-1}$ in the prime field of integers modulo $1000000007(10^9+7)$.\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\r\n2 1\r\n3 2\r\n100 1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n875000008\r\n500000029\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}