It looks like you're new here. If you want to get involved, click one of these buttons!
Time limit: 2 s
Memory limit: 64 MB
FizzBuzz is a question that is often asked at a job interview software developers. To make it more challenging, before allowance Gemastik starts, you will resolve difficult version of the question: FizzBuzz ++!
You have K fruit of rules, each of which consists of over integers M [i] and the string S [i]. Create a program that prints numbers from 1 to N, one by one, one line for each number. However, for each multiple of M [i], instead of printing the numbers, print S [i]. If there is a number that is a multiple of several M, S print consecutively starting from the smallest M in the same line.
The first line contains an integer T which specifies the number of test cases.
For each test case, the first line contains two integers N and K. K next row each contain an integer M [i] and a string S [i].
For each test case, remove the N pieces of line in accordance with the rules on the matter.
1 ≤ T ≤ 20
1 ≤ N ≤ 1000
1 ≤ K ≤ 20
1 ≤ M [i] ≤ 1.000
S [i] consisting of 1 to 5 characters a - z
The values of M [i] guaranteed unique and ascending sequences on input