Falcom is a historical company whose work "Ys VIII -Lacrimosa of DANA-" is highly acclaimed.
Remoon wants to get the platinum trophy of this game for all versions, and he notices that the game has n versions, indexed from 1 to n. A quick way to achieve this is to copy data between different versions. Unfortunately, due to compatibility issues, data in each version cannot be loaded in other versions. Nevertheless, remoon gets n−1 editors, where the i-th editor can rewrite data in version ui, such that the rewritten data can be loaded in version vi. It is also possible to use the i-th editor to change data in version vi to data in version ui. It is guaranteed that any two versions can transform into each other through the n−1 editors.
To distinguish between each version, remoon gives each version j a magic integer aj. If for any editor, aui≠avi. Then remoon can distinguish whether the editor has correctly rewritten a version or not. Besides, to limit the magic number's size, remoon gives an upper bound integer sequence b1,...,bn and require that for i∈{1,2,...,n}, we have 1≤ai≤bi.
Remoon wonders how many ways to choose a1,...,an so that he can correctly distinguish between the versions. Two ways a1,...,an and a1′,...,an′ are considered different if and only if there exists 1≤i≤n such that ai≠ai′. As the answer may be too large, you only need to output the answer modulo 998244353.