Ahoy, Pirates!

In the ancient pirate ages, the Pirate Land was divided into two teams of pirates, namely, the Buccaneer and the Barbary pirates. Each pirate’s team was not fixed, sometimes the opponent pirates attacked and he was taken away to the other pirate team. All on a sudden a magician appeared in the Pirate Land, where he was making transition of pirates from their team to other team at his own will. Of course, handy spells were used. The process of changing team was known as mutating. There were N pirates and all of the pirates have a unique id from 0 to N − 1. The great magician could mutate a bunch of pirates with consecutive id’s to another one. Suppose there were 100 pirates in the pirate land and all of them were Barbary pirates, then the magician could cast a spell to change pirates with id’s from 10 to 33 to Buccaneer pirates. Then the whole pirate land would have 24 Buccaneer and 76 Barbary pirates. The magician was very fast casting the spell. Once, God started to dislike this. God had favor for the Buccaneer pirates and God asked the magician, “Tell me, how many of the pirates of index from 2 to 30 are Buccaneer pirates?”. Now the magician was puzzled as he was only efficient in casting spells, not in counting :-) Being clever enough, the magician captured a clever man from the Earth Land. And unfortunately its you! Now you have to answer the Gods questions. Input The first line of input will contain number of test cases T. For each test case: The first part of the description will be of the pirate land. There could be up to N (1 ≤ N ≤ 1024000) pirates. Each pirate is either assigned to Buccaneer or Barbary Pirate. Buccaneer pirates are described by ‘1’ (ONE) and Barbary pirates are described by ‘0’ (ZERO). You have to build a string of the pirates description. Each case starts with an integer M (M ≤ 100), where M pair lines follow. In each pair of lines (we call it a set), first has an integer T (T ≤ 200) and next one has a nonempty string Pirates (consisting of 0 and 1, 0 for Barbary, 1 for Buccaneer, has maximum length of 50). For each pair concatenate the string Pirates, T times. Concatenate all the resulting M sets of strings to build the pirate description. The final concatenated string describes the pirates from index 0 to end (N − 1 for N pirates). Now the next part of the input will contain queries. First line of next part has an integer Q describing number of queries. Each subsequence Q (1 ≤ Q ≤ 1000) lines describe each query. Each query has a string F or E or I or S and two integers, a and b denoting indexes. The meaning of the query string are follows: F a b, means, mutate the pirates from index a to b to Buccaneer Pirates. E a b, means, mutate the pirates from index a to b to Barbary Pirates. I a b, means, mutate the pirates from index a to b to inverse pirates. S a b, means, “God’s query” God is asking a question: “Tell me, how many Buccaneer pirates are there from index a to b?” (a ≤ b, 0 ≤ a < n, 0 ≤ b < n, index range are inclusive) Output For each test print the case number as the sample output suggests. Then for each of God’s query, output the query number, colon (:) and a space and the answer to the query as the sample suggest. Explanation:

2/2 Case1: The pirate land is as follows (N = 18) 101010101010001000 Before God’s first query it was as follows 000000111111111111 Case 2: The pirate land is as follows (N = 9) 111000000 Sample Input 2 2 5 10 2 1000 5 F 0 17 I05 S 1 10 E49 S 2 10 3 3 1 4 0 2 0 2 I02 S08 Sample Output Case 1: Q1: 5 Q2: 1 Case 2: Q1: 0