{"raw_statement":[{"iden":"statement","content":"Time goes so quickly; remember *Bakkar*’s & *Maymona*’s anniversary two years ago when *Bakkar* bought a smartphone as a surprise gift for *Maymona*? Well *Maymona* had also a joyful surprise for *Bakkar*. *Maymona* was pregnant. \n\nMonths later *Maymona* gave birth to a beautiful baby and they decided to call him *Mahdi*. They were really so excited about their first child and decided to do their best to raise him up well. *Mahdi* is now about one year old and started to learn how to talk. As *Bakkar* & *Maymona* are geeks they had a very creative idea to teach *Mahdi* how to talk and evaluate his progress. \n\nSimply they programmed a little teddy bear to speak so *Mahdi* can repeat after him. When *Mahdi* repeats what the teddy bear just said it recognises the word and analyse it. And as we all know its very natural that kids don’t spell all letters at the beginning. So what *Bakkar* & *Maymona* thought to evaluate the correctness and progress of what *Mahdi* says is to check if the work *Mahdi* repeats after the teddy bear is a subsequence of the original word the teddy bear just said. To evaluate *Mahdi*’s progress the teddy bear defines a subsequence of a string *y* if it can be produced by deleting some of the characters in *y*. For example, \"ace\" is a subsequence of \"adcbe\" but not a subsequence of \"bcae\". If *Mahdi* spells a subsequence it is considered to be a positive indicator that *Mahdi* is progressing. To motivate *Mahdi* when he spells something correctly according to what we mentioned; if he spells a subsequence of the original word the teddy bear would respond with ‘bravo’ and start clapping, Otherwise he would repeat the word again several times until so *Mahdi* can take his time practicing. \n\nThe teddy bear is programmed in a very simple and creative way. He says random words based on an equation that *Bakkar* & *Maymona* invented. They specify a starting character to start the word, the length of the word, adder and multiplier. Simply the word is generated as follows:\n\ns0 = starting character\n\nsi = char((pos(si - 1) * multiplier + i * adder) % 26)\n\nWhere:\n\npos(a) = 0, pos(b) = 1, ....pos(z) = 25\n\nchar(0)= a, char(1)= b,.....char(25)= z\n\nHmmmmm, *Bakkar* & *Maymona* are so busy; *Bakkar* at his work and *Maymona* taking care of the house and *Mahdi*. And as you are one of their best friends and still single and have some spare time you proposed to program the teddy bear for them. Besides you are the voice recognition geek among their friends ;).\n\nFor simplicity the words *Mahdi* repeats will be generated using the same equation the teddy bear uses.\n\nThe first line will be an integer T (1  ≤  T  ≤  10) the number of test cases. Each test case will start by a line containing 1 character and 3 integers (length, multiplier, adder) for the string *S* as described above (1  ≤  length(S)  ≤  107). The next line will contain a single integer *N* (1  ≤  *N*  ≤  104) the number of strings *Mahdi* repeats. The next *N* lines each contain 1 character and 3 integers (length, multiplier, adder) for the string Li as described above. The starting character will be a lowercase character, (1  ≤  length(Li)  ≤  100), \n\n1  ≤  multiplier, adder  ≤  1000.\n\nFor each test, For each test case print a single line containing \"Case n:\" (without the quotes) where n is the test case number (starting from 1) followed by N lines each containing either \"BRAVO\" (without quotes) if Li is a subsequence of S and *Mahdi* is making a progress or \"REPEAT\" (without quotes) otherwise.\n\nfor input d 5 31 12, the string will be\n\ns0 = d\n\ns1 = char((pos(d) * 31 + 1 * 12)%26) = char((3 * 31 + 1 * 12)%26) = char(105%26) = char(1) = b\n\ns2 = char((pos(b) * 31 + 2 * 12)%26) = char((1 * 31 + 2 * 12)%26) = char(55%26) = char(3) = d\n\ns3 = char((pos(d) * 31 + 3 * 12)%26) = char((3 * 31 + 3 * 12)%26) = char(129%26)= char(25) = z\n\ns4 = char((pos(z) * 31 + 4 * 12)%26) = char((25 * 31 + 4 * 12)%26) = char(823%26) = char(17) = r\n\nso the string is \"dbdzr\"\n\n*Warning: large Input/Output data, be careful with certain languages.*\n\n"},{"iden":"input","content":"The first line will be an integer T (1  ≤  T  ≤  10) the number of test cases. Each test case will start by a line containing 1 character and 3 integers (length, multiplier, adder) for the string *S* as described above (1  ≤  length(S)  ≤  107). The next line will contain a single integer *N* (1  ≤  *N*  ≤  104) the number of strings *Mahdi* repeats. The next *N* lines each contain 1 character and 3 integers (length, multiplier, adder) for the string Li as described above. The starting character will be a lowercase character, (1  ≤  length(Li)  ≤  100), 1  ≤  multiplier, adder  ≤  1000."},{"iden":"output","content":"For each test, For each test case print a single line containing \"Case n:\" (without the quotes) where n is the test case number (starting from 1) followed by N lines each containing either \"BRAVO\" (without quotes) if Li is a subsequence of S and *Mahdi* is making a progress or \"REPEAT\" (without quotes) otherwise."},{"iden":"examples","content":"Input1a 100 13 373a 11 11 311b 9 13 22d 5 31 12OutputCase 1:REPEATREPEATBRAVO"},{"iden":"note","content":"for input d 5 31 12, the string will bes0 = ds1 = char((pos(d) * 31 + 1 * 12)%26) = char((3 * 31 + 1 * 12)%26) = char(105%26) = char(1) = bs2 = char((pos(b) * 31 + 2 * 12)%26) = char((1 * 31 + 2 * 12)%26) = char(55%26) = char(3) = ds3 = char((pos(d) * 31 + 3 * 12)%26) = char((3 * 31 + 3 * 12)%26) = char(129%26)= char(25) = zs4 = char((pos(z) * 31 + 4 * 12)%26) = char((25 * 31 + 4 * 12)%26) = char(823%26) = char(17) = rso the string is \"dbdzr\"*Warning: large Input/Output data, be careful with certain languages.*"}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $:  \n- Let $ S_k $ be a string of length $ L_k $, generated recursively:  \n  - $ s_0 = c_0 $, where $ c_0 $ is a starting lowercase character.  \n  - For $ i \\in \\{1, \\dots, L_k - 1\\} $:  \n    $$\n    s_i = \\text{char}\\left( \\left( \\text{pos}(s_{i-1}) \\cdot m_k + i \\cdot a_k \\right) \\bmod 26 \\right)\n    $$  \n    where $ \\text{pos}(x) = x - 'a' $, $ \\text{char}(p) = 'a' + p $, and $ m_k, a_k \\in \\mathbb{Z} $ are multiplier and adder.  \n\n- Let $ N_k \\in \\mathbb{Z} $ be the number of strings $ L_{k,j} $ (for $ j \\in \\{1, \\dots, N_k\\} $) spoken by Mahdi.  \n  Each $ L_{k,j} $ is a string of length $ \\ell_{k,j} $, generated similarly:  \n  - $ t_0 = c_{k,j} $ (starting character),  \n  - For $ i \\in \\{1, \\dots, \\ell_{k,j} - 1\\} $:  \n    $$\n    t_i = \\text{char}\\left( \\left( \\text{pos}(t_{i-1}) \\cdot m_{k,j} + i \\cdot a_{k,j} \\right) \\bmod 26 \\right)\n    $$  \n    with parameters $ m_{k,j}, a_{k,j} \\in \\mathbb{Z} $.  \n\n**Constraints**  \n1. $ 1 \\le T \\le 10 $  \n2. For each test case $ k $:  \n   - $ 1 \\le L_k \\le 10^7 $, $ 1 \\le m_k, a_k \\le 1000 $  \n   - $ 1 \\le N_k \\le 10^4 $  \n   - For each $ j \\in \\{1, \\dots, N_k\\} $:  \n     - $ 1 \\le \\ell_{k,j} \\le 100 $, $ 1 \\le m_{k,j}, a_{k,j} \\le 1000 $  \n\n**Objective**  \nFor each test case $ k $, and for each $ j \\in \\{1, \\dots, N_k\\} $:  \n- Output \"BRAVO\" if $ L_{k,j} $ is a subsequence of $ S_k $,  \n- Otherwise output \"REPEAT\".","simple_statement":"Given a generated string S and N generated strings L_i, check if each L_i is a subsequence of S. For each, output \"BRAVO\" if yes, \"REPEAT\" if no.","has_page_source":false}