SPOJ FizzBuzz++

FizzBuzz ++

Time limit: 2 s

Memory limit: 64 MB

 

Description

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.

Input format

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].

output format

For each test case, remove the N pieces of line in accordance with the rules on the matter.

Sample Input

3
10 2
3 fizz
5 buzz
20 3
2 know
4 hi
5 halo
5 2
1 a
2 b
Sample output

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
1
you know
3
lhohai
Hello
you know
7
lhohai
9
lhohalo
11
lhohai
13
you know
Hello
lhohai
17
you know
19
lhohaihalo
a
ab
a
ab
a
restriction

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

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories