

Kevin has recently learned the concept of “STACK”. During his practice, he got stuck in a problem where he has to reverse a string ‘S’ using a stack. So, he appoints you to help him in reversing the string ‘S’. All you have to do is to find the reversed string.
Please reverse the string using a stack so that Kevin gets to know where he is getting wrong after seeing your solution. It is guaranteed that strings will only be composed of English alphabets.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain a string ‘S’.
Output Format:
For each test case, return the reversed string.
Output for every test case will be printed in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= |S| <= 10^4
Time limit: 1 sec
2
CODINGNINJAS
WelcomeToCodeStudio
SAJNINGNIDOC
oidutSedoCoTemocleW
In the first test case, the reverse of the given string is “SAJNINGNIDOC”.
In the second test case, the reverse of the given string is “oidutSedoCoTemocleW”.
3
A
Aa
aA
A
aA
Aa
In the first test case, the reverse of the given string is “A”.
In the second test case, the reverse of the given string is “aA”.
In the third test case, the reverse of the given string is “Aa”.
Put each character in the stack and then remove one by one.
The basic idea is to push the whole string into a stack (character by character) and then take off each character from the stack one by one. The steps are as follows:
O(N), where ‘N’ is the length of the given string ‘S’.
Since we are iterating through the string once, so the time complexity will be O(N). Push and pop functions take constant time in the case of the stack. Thus, the overall time complexity is O(N).
O(N), where ‘N’ is the length of the given string ‘S’.
We are using a stack to store each string’s character, so the space complexity is O(N).