#arc123e. [arc123_e]Training

[arc123_e]Training

Problem Statement

Two programmers, XX and YY, are going to start competitive programming.

One's skill in competitive programming is represented by a positive integer called the level. Initially, XX's level is AXA_X, and YY's level is AYA_Y. The two will do learning tasks to raise their levels.

We know that they level up as follows.

  • XX's level raises by one after every BXB_X learning tasks.
  • YY's level raises by one after every BYB_Y learning tasks.

How many among n=1,2,ldots,Nn = 1, 2, \\ldots, N satisfy the following?

  • XX's level and YY's level are equal when each of them has done exactly nn learning tasks.

Process TT test cases per input file.

Constraints

  • 1leqTleq2times1051\\leq T\\leq 2\\times 10^5
  • 1leqNleq1091\\leq N\\leq 10^{9}
  • 1leqAX,BX,AY,BYleq1061\\leq A_X, B_X, A_Y, B_Y \\leq 10^6

Input

Input is given from Standard Input in the following format:

TT textcase1\\text{case}_1 textcase2\\text{case}_2 vdots\\vdots textcaseT\\text{case}_T

Each case is in the following format:

NN AXA_X BXB_X AYA_Y BYB_Y

Output

Print the answers.


Sample Input 1

5
10 5 3 4 2
5 5 3 4 2
100 5 3 4 2
10 5 3 4 3
10 5 10 5 9

Sample Output 1

6
3
6
0
9

We will describe the first test case.

For each n=1,2,ldots,10n = 1, 2, \\ldots, 10, the two's levels after doing nn learning tasks are as follows.

  • XX's level: 5,5,6,6,6,7,7,7,8,85, 5, 6, 6, 6, 7, 7, 7, 8, 8.
  • YY's level: 4,5,5,6,6,7,7,8,8,94, 5, 5, 6, 6, 7, 7, 8, 8, 9.

There are six scenarios (n=2,4,5,6,7,9n = 2, 4, 5, 6, 7, 9) where the two's levels are equal, so the answer is 66.