Competitions

# Binary Tree

Binary Tree is a tree data structure where each node has at most two children, usually they are distinguished as left and right child. And the node having the children are called parent of those children.

An instruction string is a string consisting of the letters L, R and U. L stands for Left, R for Right and U for Up. Meaning of these will be clear shortly.

One day I have drawn an infinitely large Binary Tree. In this tree each node has exactly two children (left child and right child) and each of them has a parent. For this problem, we will consider the parent of the root is root itself. I put a pen in the root and follow the instruction string S. That is, we look at the first character if it says L we go to left child, if it says R we go to right child and if it says U then to the parent. If we receive a U instruction at root we just end up at root since we assumed parent of the root is root itself.

Now we have another instruction string T. Starting from the node where we are after following the instruction string S, we will follow the instruction string T. But this time, if we wish we may skip any instruction in the string T (possibly discarding all of them). You have to tell me how many different nodes I can end up after following instruction string T (skipping as many instructions as I wish).

For example:

Suppose: S = L and T = LU. Our answer is 3. Following S we will end up at the left child of the root. Now, when we follow T, there may be 4 cases:

1. Skipping all letters: we will be at the same node where we are.
2. Skipping L and following U: we will be at the root.
3. Following L and Skipping U: we will be at the left child of current node.
4. Following both L and U: we will be at the same node as in case 1.

Since 3 different nodes we can end up after following T, the answer is 3.

Input

First line contains the number of test cases n (n 15). Hence follow n test cases. Each test case consists of two non empty strings. First line will contain instruction string S and the second line will contain the instruction string T. You may assume that there will not be any letter other than L, R or U in these strings. Length of the strings will not be greater than 100000.

Output

For each test case print the case number followed by the number of nodes we can end up finally. Since the answer may be large, you have to give the answer modulo 21092013.

Time limit 1 second
Memory limit 64 MiB
Input example #1
2
L
LU
L
L

Output example #1
Case 1: 3
Case 2: 2

Source 2013 ACM Southwestern Europe Regional Contest (SWERC), November 17
{"ft_lang_label":"__label__en","ft_lang_prob":0.92196935,"math_prob":0.93678236,"size":2468,"snap":"2022-27-2022-33","text_gpt3_token_len":576,"char_repetition_ratio":0.16233766,"word_repetition_ratio":0.04684318,"special_character_ratio":0.23865478,"punctuation_ratio":0.098148145,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97935766,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-11T01:32:17Z\",\"WARC-Record-ID\":\"<urn:uuid:c9bb2d67-ed07-4b41-a507-f96d3a83daa3>\",\"Content-Length\":\"11101\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1fdb78d2-37b6-4e1a-a141-5aa4fb5f11b4>\",\"WARC-Concurrent-To\":\"<urn:uuid:0568e655-6b19-4a5f-a7f0-b807d38446ab>\",\"WARC-IP-Address\":\"52.29.209.31\",\"WARC-Target-URI\":\"https://www.eolymp.com/en/contests/7678/problems/63705\",\"WARC-Payload-Digest\":\"sha1:I65A5OTPYTM7SQ7CEQGRASXDTLNDESQ2\",\"WARC-Block-Digest\":\"sha1:PROZOJLBGFFO2M5II2PAEXHFQ3LGHCVX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882571232.43_warc_CC-MAIN-20220811012302-20220811042302-00142.warc.gz\"}"}