{"problem":{"name":"Training","description":{"content":"Two programmers, $X$ and $Y$, are going to start competitive programming. One's skill in competitive programming is represented by a positive integer called the _level_. Initially, $X$'s level is $A_X","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":3000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc123_e"},"statements":[{"statement_type":"Markdown","content":"Two programmers, $X$ and $Y$, are going to start competitive programming.\nOne's skill in competitive programming is represented by a positive integer called the _level_. Initially, $X$'s level is $A_X$, and $Y$'s level is $A_Y$. The two will do learning tasks to raise their levels.\nWe know that they level up as follows.\n\n*   $X$'s level raises by one after every $B_X$ learning tasks.\n*   $Y$'s level raises by one after every $B_Y$ learning tasks.\n\nHow many among $n = 1, 2, \\ldots, N$ satisfy the following?\n\n*   $X$'s level and $Y$'s level are equal when each of them has done exactly $n$ learning tasks.\n\nProcess $T$ test cases per input file.\n\n## Constraints\n\n*   $1\\leq T\\leq 2\\times 10^5$\n*   $1\\leq N\\leq 10^{9}$\n*   $1\\leq A_X, B_X, A_Y, B_Y \\leq 10^6$\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$T$\n$\\text{case}_1$\n$\\text{case}_2$\n$\\vdots$\n$\\text{case}_T$\n\nEach case is in the following format:\n\n$N$ $A_X$ $B_X$ $A_Y$ $B_Y$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc123_e","tags":[],"sample_group":[["5\n10 5 3 4 2\n5 5 3 4 2\n100 5 3 4 2\n10 5 3 4 3\n10 5 10 5 9","6\n3\n6\n0\n9\n\nWe will describe the first test case.\nFor each $n = 1, 2, \\ldots, 10$, the two's levels after doing $n$ learning tasks are as follows.\n\n*   $X$'s level: $5, 5, 6, 6, 6, 7, 7, 7, 8, 8$.\n*   $Y$'s level: $4, 5, 5, 6, 6, 7, 7, 8, 8, 9$.\n\nThere are six scenarios ($n = 2, 4, 5, 6, 7, 9$) where the two's levels are equal, so the answer is $6$."]],"created_at":"2026-03-03 11:01:14"}}