Rikka with Proper Fractions

분모가 n 이하인 기약분수 중 주어진 구간에 들어가는 것의 개수를 998244353으로 나눈 나머지를 구한다.

어려움9정수론수학조합론구현아직 제출이 없습니다시간 제한10초메모리 제한512 MB

문제

Rikka is a lovely girl. Although she was not good at math before, she has made great progress with the help of her boyfriend Yuta. And Rikka has been able to do math research by herself now.

Today, Rikka is reading some materials about rational number approximation. Rikka is interested in the continuous fractional expansion algorithm which can find the closest fraction ab\frac{a}{b} to approximate a given number xx among all the fractions with denominator less than nn.

Rikka wants to estimate the difficulty of this problem. She picks a fraction ab\frac{a}{b} which is less than xx and picks a fraction cd\frac{c}{d} which is greater than xx. And she wants to find the number of rational numbers in the interval \[ab,cd]\[\frac{a}{b},\frac{c}{d}] which can be represented by fractions with denominators less than or equal to nn. Formally, given ab\frac{a}{b}, cd\frac{c}{d}, and nn, Rikka wants to find the number of proper fractions ef\frac{e}{f} (1e<fn1 \leq e < f \leq n, gcd(e,f)=1)\mathrm{gcd}(e, f) = 1) which satisfy abefcd\frac{a}{b} \leq \frac{e}{f} \leq \frac{c}{d}.

This task seems too hard for Rikka. Please help her find the answer.

입력

The first line contains a single integer tt (1t1031 \leq t \leq 10^3), the number of test cases.

Each test case is given on a separate line containing five integers nn, aa, bb, cc, and dd (0<ab<cd<10 < \frac{a}{b} < \frac{c}{d} < 1, 1a,b,c,d1081 \leq a, b, c, d \leq 10^8).

It is guaranteed that both ab\frac{a}{b} and cd\frac{c}{d} are proper fractions, 1n10101 \leq n \leq 10^{10}, and there are at most 33 test cases with n>106n > 10^6.

출력

For each test case, output a single line with a single integer: the answer modulo 998,244,353998\\,244\\,353.