{"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":"\u003cp\u003eOut of our universe, there is a little planet named Klyntar. In Klyntar, a country is entirely colonized by Scientists. There are a total of N Scientists, and the interesting fact is that each scientist lives in their own city due to their unique research environment. There is a point that two cities are not connected to each other by road because scientists communicate online or by reviewing research papers. Cities are often identified with numbers ranging from 1 to $$$N$$$.\u003c/p\u003e\n\u003cp\u003eEverything was perfect—until one scientist chose to use their smartphone to compose a research report. The term \"self-evident\" was autocorrected on the smartphone to \"Pictionary,\" and the report was then published as such. Soon, the whole country discovered Pictionary and wanted to get together and play. As a result, road construction work between two cities began soon.\u003c/p\u003e\n\u003cp\u003eThe road construction work will take $$$M$$$ days in total. In accordance with the following plan:\u003c/p\u003e\n\u003cp\u003eDay 1: Road construction is done between all pairs of cities that have $$$M$$$ as their greatest common divisor.\u003c/p\u003e\n\u003cp\u003eDay 2: Road construction is done between all pairs of cities that have $$$M-1$$$ as their greatest common divisor.\u003c/p\u003e\n\u003cp\u003eAnd so on until the $$$M$$$th day when construction is done on roads between all pairs of cities that are co-prime. More formally, on the $$$i$$$th day, construction is done on roads between cities $$$a$$$ and $$$b$$$ if $$$\\gcd(a, b) \u003d M - i + 1$$$.\u003c/p\u003e\n\u003cp\u003eSince the mathematicians are busy with construction work, they\u0027ve asked you to help them determine the minimal number of days before a given pair of mathematicians can play pictionary together.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of input contains three positive integers N, M and Q ($$$1 \\leq N$$$, $$$Q \\leq 10^5$$$, $$$1 \\leq M \\leq N$$$), the number of cities, the number of days it takes to build the roads, and the number of queries.\u003c/p\u003e\n\u003cp\u003eEach of the following Q lines contains two distinct positive integers A and B ($$$1 \\leq A, B \\leq N$$$) that denote the cities of the scientists who want to find out the minimal number of days before they can play pictionary together.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eThe $$$i$$$th line must contain the minimal number of days before the scientists from the $$$i$$$th query can play pictionary together.\u003c/p\u003e"}},{"title":"Sample 1","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\u003e8 3 3\n2 5\n3 6\n4 8\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\n1\n2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Sample 2","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\u003e25 6 1\n20 9\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Sample 3","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\u003e9999 2222 2\n1025 2405\n3154 8949\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1980\n2160\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}