{"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\u003eArchmage(简称AM)是Watercraft III中的英雄单位。\u003c/p\u003e\n\u003cp\u003e他最多有n法力值和两个强大的技能,让他在战斗中展现出强大的力量:\u003c/p\u003e\n\u003col\u003e \n \u003cli\u003e 使用 $$$x$$$ 法力召唤一个水元素。 \u003c/li\u003e\n \u003cli\u003e Brilliance Aura 每秒为 AM 恢复 $$$y$$$ 法力,这是\u003cspan class\u003d\"tex-font-style-bf\"\u003e唯一\u003c/span\u003e恢复法力的方式。既然他的法力不能超过上限,多余的法力就会消散。即假设您在恢复之前有 $$$p$$$ 法力,则您的法力将变为 $$$\\min(p+y,n)$$$。\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003e由于大法师的力量是巨大的,法力上限$n$总是大于等于$x+y$。\u003c/p\u003e\n\u003cp\u003e每一秒,大法师都会召唤\u003cspan class\u003d\"tex-font-style-bf\"\u003e恰好一个\u003c/span\u003e水元素(如果法力足够,即他的法力不会低于$0$之后)或什么都不做。那么无论他之前做什么,他都会恢复$y$法力。\u003c/p\u003e\n\u003cp\u003e大法师在第二个 $$$0$$$ 结束时有 $$$n$$$ 法力,游戏在第二个 $$$1$$$ 开始时开始。\u003c/p\u003e\n\u003cp\u003e他想知道自己在第二个 $$$m$$$ 结束前最多可以召唤多少个水系元素。\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003e输入由多个测试用例组成。 \u003c/p\u003e\n\u003cp\u003e第一行包含一个整数 $$$t(1 \\leq t \\leq 10^5)$$$,表示测试用例的数量。\u003c/p\u003e\n\u003cp\u003e接下来的每一行 $$$t$$$ 包含 $$$4$$$ 个整数 $$$n,m,x,y(1 \\leq m,x,y \\leq 10^9,x+y \\leq n \\leq 2 \\times 10^9)$$$。\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003e对于每个测试用例,在一行中输出答案。\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\n2 2 1 1\n4 4 2 1\n6 10 4 2\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\u003e2\n3\n6\n\u003c/pre\u003e\n \u003c/div\u003e\n\u003c/div\u003e"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003e在测试案例 $$$1$$$ 中,Archmage 每秒可以施放法术,所以答案是 $$$2$$$。\u003c/p\u003e\n\u003cp\u003e在测试案例 $$$2$$$ 中,这是大法师施放法术 $$$3$$$ 次的方法。\u003c/p\u003e\n\u003cp\u003e第二个$1$:大法师施法,剩余$4-x+y\u003d3$法力。\u003c/p\u003e\n\u003cp\u003e第二个$2$:大法师施法,剩余$3-x+y\u003d2$法力。\u003c/p\u003e\n\u003cp\u003e第二个$3$:大法师施法,剩余$2-x+y\u003d1$法力。\u003c/p\u003e\n\u003cp\u003e第二个$4$:大法师法力不足,无能为力,只剩下$1+y\u003d2$法力。\u003c/p\u003e"}}]}