#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 100005
void reverse_and_remove_spaces(char* str, char* result) {
int len = strlen(str);
int index = 0;
// Remove spaces
for (int i = 0; i < len; i++) {
if (str[i] != ' ') {
result[index++] = str[i];
}
}
result[index] = '\0'; // Null-terminate the result string
// Reverse the result string
int start = 0;
int end = index - 1;
while (start < end) {
char temp = result[start];
result[start] = result[end];
result[end] = temp;
start++;
end--;
}
}
int main() {
int t;
scanf("%d", &t);
// To handle large inputs efficiently
char input[MAX_LENGTH];
char result[MAX_LENGTH];
while (t--) {
int n;
scanf("%d", &n);
getchar(); // Consume the newline character left by scanf
// Read the whole line including spaces
fgets(input, MAX_LENGTH, stdin);
// Remove trailing newline character
input[strcspn(input, "\n")] = '\0';
reverse_and_remove_spaces(input, result);
// Print the result
printf("%s\n", result);
}
return 0;
}