E. ACM
time limit per test
9 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

An IT company puts out an advertisement to hire staff for a newly established office. They received n applications and organized an interview to select the best ones. They want to recruit candidates with both high level of expertise and good teamwork skill. Each candidate is assigned an ACM (Ability Coefficient of Multi-collectives) score that represents how the candidate meets the company’s internal selection criteria. Initially, everyone’s ACM score is 1.

Candidates are arranged into a round table of n seats, indexed from 1 to n. The first person sits next to the second person and the nth person. For each interview question, candidates with indices from L and R form a group and register their collective answer to the system. If L ≤ R, the group consists of candidates at indices L, L + 1, L + 2, ..., R. If L > R, the group consists of candidates at indices L, L + 1, ..., N, 1, ..., R. Depending on the answer, the ACM score of each group member is either multipled by X or divided by Y (in the later case, it is guaranteed that all ACM scores of the group are divisible by Y).

During the interview, the company may also request the system to output the product of the ACM scores of a group. This product could be a large number, so the system has to only output the value at modulo P. In summary, the system has to handle the following three types of queries:

  • 0 L R P – compute the product of the ACM scores of all candidates from L to R, modulo P
  • 1 L R X – the ACM score of each candidate from L to R is multiplied by X
  • 2 L R Y – the ACM score of each candidate from L to R is divided by Y

For every query, we have 1 ≤ L, R ≤ N, 1 ≤ P ≤ 109 + 7, 1 ≤ X, Y ≤ 150.

Your task is to implement the system and output the computed products for every query of type 0.

Input

The input file consists of several datasets. The first line of the input file contains the number of datasets which is a positive integer and is not greater than 20. The following lines describe the datasets.

Each dataset comes in the following format:

  • The first line contains 2 integers n, m where n is the number of candidates and m is the number of queries to be processed (1 ≤ n, m ≤ 50000).
  • In the next m lines, the ith line contains the ith query.
Output

For each dataset, write out the corresponding outputs for queries of type 0 where each query output is on a separate line.

Examples
Input
2
6 5
0 1 5 1000000007
1 2 4 15
0 1 6 8704173
2 2 3 3
0 1 6 1000000007
6 6
1 1 4 20
1 2 6 15
0 1 6 9704331
2 3 6 5
0 1 4 1000000007
0 1 5 1000000007
Output
1
3375
375
1775880
21600000
64800000