// Arup Guha
// 8/31/2021
// Utility file that splits deck input by suit and kind so it's easier to eyeball.

#include <stdio.h>
#include <string.h>

#define DECKSIZE 52

int main(void) {

    int nC;
    scanf("%d", &nC);

    // Process each case.
    for (int loop=0; loop<nC; loop++) {

        // Read in the whole deck and concatenate into the same string.
        char deck[2*DECKSIZE+1], secondHalf[DECKSIZE+1];
        scanf("%s%s", deck, secondHalf);
        strcat(deck, secondHalf);

        // Prints suits.
        for (int i=0; i<DECKSIZE; i++)
            printf("%c", deck[2*i+1]);
        printf("\n");

        // Prints kinds.
        for (int i=0; i<DECKSIZE; i++)
            printf("%c", deck[2*i]);
        printf("\n");
    }

    return 0;
}
