Recently Arya the little panda got a permutation of size as a birthday present from his parents. Being a crazy little panda, he decided to make some operations on it. In each operation he chooses some index and moves to the front of the permutation.
Let's say the initial permutation is ( 3, 5, 4, 1, 6, 2 ) and the sequence of operations is ( 3, 2, 5). So after the 1st operation, the permutation becomes, ( 4, 3, 5, 1, 6, 2 ) After the 2nd operation, the permutation becomes, ( 3, 4, 5, 1, 6, 2 ) After the 3rd operation, the permutation becomes, ( 6, 3, 4, 5, 1, 2 )
Arya has the initial permutation and the final permutation, he also remembers how many operations were made but he forgot the sequence of operations. Now he wonders, how many sequence of operations could there be? As the number can be quite large, output it modulo 998244353.
First line of input consists of a single integer , the number of test cases
Each test case consists of two lines as follows :
First line of the test case contains , the length of permutation and , the length of operation sequence ().
Second line contains space-separated distinct integers, denoting the initial permutation ( ).
Third line contains space-separated distinct integers, denoting the final permutation ( ).
For each testcase print one integer, the possible number of operation sequences of length modulo 998244353 . Two sequences are considered different if there is atleast one index where they differ.
1 4 2 3 2 4 1 1 3 2 4
We call a sequence of integers permutation if every integer from to appears exactly once in the sequence, where denotes the length of the sequence.
0% Solution Ratio
Login to submit