// Arup Guha
// 8/16/2021
// Solution to COP 3502 Fall 2021 Program 0: Deck

#include <stdio.h>
#include <string.h>

#define DECKSIZE 52

int samesuit(char* deck);
int longascending(char* deck);
int getValue(char c);
int isSuccessor(char c1, char c2);

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);

        // Give to functions to solve and print results!
        printf("%d %d\n", samesuit(deck), longascending(deck));
    }
    return 0;
}

// Returns the length of the longest same suit run in the cards represented in deck.
int samesuit(char* deck) {

    // Beginning answers.
    int len = strlen(deck);
    int res = 1, cur = 1;
    char curSuit = deck[1];

    // Suits are every other...
    for (int i=3; i<len; i+=2) {

        // Add to this streak.
        if (deck[i] == curSuit) {
            cur++;
            if (cur > res) res = cur;
        }

        // Start a new streak.
        else {
            cur = 1;
            curSuit = deck[i];
        }
    }

    // Ta da!
    return res;
}

// Returns the length of the longest ascending run in the cards represented by deck.
int longascending(char* deck) {

    int len = strlen(deck);
    int res = 1, cur = 1;

    // Kinds are every other...
    for (int i=2; i<len; i+=2) {

        // Add to this streak.
        if (isSuccessor(deck[i-2], deck[i])) {
            cur++;
            if (cur > res) res = cur;
        }

        // Start a new streak.
        else {
            cur = 1;
        }
    }

    // Ta da!
    return res;
}

// Returns a 0-12 value of a card. ('2' = 0, '3' = 1, ..., 'A' = 12)
int getValue(char c) {

    // Numeric cards.
    if (c >= '2' && c <= '9') return c - '2';

    // Just case these out.
    if (c == 'T') return 8;
    if (c == 'J') return 9;
    if (c == 'Q') return 10;
    if (c == 'K') return 11;
    return 12;
}

// Returns 1 iff c2 is the successor of c1.
int isSuccessor(char c1, char c2) {

    // Get the card values.
    int v1 = getValue(c1);
    int v2 = getValue(c2);

    // Use mod to handle the wrap around case.
    return (v1+1)%13 == v2;
}
