

1. Append string ‘A’ to C one time.
2. Append string ‘B’ to C two times.
3. Append string ‘A’ to C three times.
4. Append string ‘B’ to C four times.
5. Append string ‘A’ to C five times.
And so on….
If ‘A’ = “AB” and B = “CD” and K = 7.
The formed string will be “ABCDCDABABAB…...”.
So, the 7th character is A.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains two strings, 'A’ and ’B’.
The second line contains ‘K’ representing the character number to be found.
For each test case, print a character denoting the ‘K’th character.
Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= length of ‘A’,length of ‘B’ <= 100.
1 <= ‘K’ <= 10^15
Time limit: 1 sec
In this approach, we will first declare a string ‘STRING_SIZE’ to store the size of the newly formed string.
Now, we will update the ‘STRING_SIZE’ according to the given conditions until ‘STR’ is less than ‘K’. After that, we will check if the last inserted strings are strings ‘A’ or ‘B’.We will find the number of extra added characters as ‘EXTRA’.
We will now remove the extra strings and decrease ‘EXTRA’. Now the ‘EXTRA’ + 1th character from the last of the last inserted string is the ‘K’th character of the formed string.
In the previous approach, we iterated ‘i’ from 1 to √K to make the string.
In this approach, we will run a binary search over this range and will find the smallest ‘i’ for which the 'STRING_SIZE' is greater than or equal to ‘K’.We will find the number of extra added characters as ‘EXTRA’.
We will now remove the extra strings and decrease ‘EXTRA’. Now the ‘EXTRA’ + 1th character from the last of the last inserted string is the ‘K’th character of the formed string.