SP22270 PERIOD2 - Periodic function, trip 2

Description

Milankovitch's cycle theory is an example with cumulative effect of several periodic functions. We can study past climatic patterns on Earth through orbital forcing. ![Milankovitch cycles - image](../../content/francky:Milankovitch "http://en.wikipedia.org/wiki/Milankovitch_cycles")

Input Format

The first line contains an integer _T_, the number of test cases. On the next _T_ lines, you will be given two integers _N_ and _M_. Consider the family of any finite sum of ( _n_-periodic functions with _n_ in \[1.._N_\] ). All those functions share a common smallest period.

Output Format

Print the smallest common period of that family. As the answer can get very big, simply output it modulo _M_.