#include<bits/stdc++.h>
using namespace std;

// const int ROYAL_STRAIGHT_FLUSH = 9;
const int STRAIGHT_FLUSH       = 8;
const int FOUR_OF_A_KIND       = 7;
const int FULL_HOUSE           = 6;
const int FLUSH                = 5;
const int STRAIGHT             = 4;
const int THREE_OF_A_KIND      = 3;
const int TWO_PAIRS            = 2;
const int ONE_PAIR             = 1;
const int HIGH_CARD            = 0;

pair<int, char> to_card(const string& str) {
    char suit = str[0];
    int rank;
    switch (str[1]) {
        case 'A':
            rank = 14;
            break;
        case 'K':
            rank = 13;
            break;
        case 'Q':
            rank = 12;
            break;
        case 'J':
            rank = 11;
            break;
        case 'T':
            rank = 10;
            break;
        default:
            rank = str[1] - '0';
            break;
    }
    return { rank, suit };
}

pair<int, vector<int>> get_hand(const vector<pair<int, char>>& cards) {
    int n = cards.size();
    bool is_flush = true;
    for (int i = 0; i < n - 1; ++i) {
        is_flush &= cards[i].second == cards[i + 1].second;
    }
    vector<int> cnts(15);
    for (int i = 0; i < n; ++i) {
        ++cnts[cards[i].first];
    }
    vector<int> ranks;
    for (int i = 0; i < 15; ++i) {
        if (cnts[i] > 0) {
            ranks.push_back(i);
        }
    }
    sort(ranks.begin(), ranks.end(), [&](const int& i, const int& j) { return cnts[i] != cnts[j] ? cnts[i] > cnts[j] : i > j; });
    bool is_straight = (int)ranks.size() == n && ranks[0] - ranks[n - 1] == n - 1;
    bool is_fullhouse = cnts[ranks.back()] > 1;
    int max_cnt = cnts[ranks[0]];
    int same_cnt = 1;
    for (int i = 1; i < (int)ranks.size(); ++i) {
        if (cnts[ranks[i - 1]] == cnts[ranks[i]]) ++same_cnt;
        else break;
    }
    if ((int)ranks.size() == n && ranks[0] == 14 && ranks[1] == 5) {
        is_straight = true;
        ranks = { 5, 4, 3, 2, 1 };
    }

    if (is_straight && is_flush) return { STRAIGHT_FLUSH, ranks };
    if (max_cnt == 4) return { FOUR_OF_A_KIND, ranks };
    if (is_fullhouse) return { FULL_HOUSE, ranks };
    if (is_flush) return { FLUSH, ranks };
    if (is_straight) return { STRAIGHT, ranks };
    if (max_cnt == 3) return { THREE_OF_A_KIND, ranks };
    if (max_cnt == 2 && same_cnt == 2) return { TWO_PAIRS, ranks };
    if (max_cnt == 2) return { ONE_PAIR, ranks };
    return { HIGH_CARD, ranks };
}

pair<int, vector<int>> max_hand(const vector<pair<int, char>>& cards) {
    int n = cards.size(), m = 5;
    vector<int> v(n);
    for (int i = 0; i < m; ++i) {
        v[n - i - 1] = 1;
    }
    pair<int, vector<int>> ret = { 0, { 0 } };
    do {
        vector<pair<int, char>> c;
        for (int i = 0; i < n; ++i) {
            if (v[i]) {
                c.push_back(cards[i]);
            }
        }
        auto hand = get_hand(c);
        if (ret < hand) ret = hand;

    } while (next_permutation(v.begin(), v.end()));
    return ret;
}

pair<int, char> read_card() {
    string s;
    cin >> s;
    if (s == "#") exit(0);
    return to_card(s);
}

int main() {
    cout << setprecision(9);
    while (true) {
        vector<pair<int, char>> mycards(5);
        vector<pair<int, char>> oppcards(5);
        for (int i = 0; i < 2; ++i) {
            mycards[i] = read_card();
        }
        for (int i = 0; i < 2; ++i) {
            oppcards[i] = read_card();
        }
        for (int i = 2; i < 5; ++i) {
            auto p = read_card();
            mycards[i] = p;
            oppcards[i] = p;
        }
        int win = 0, all = 0;
        string suits = "SHDC";
        for (char s1 : suits) {
            for (int r1 = 2; r1 < 15; ++r1) {
                pair<int, char> c1 = { r1, s1 };
                for (auto& c : mycards) {
                    if (c == c1)
                        goto A;
                }
                for (auto& c : oppcards) {
                    if (c == c1)
                        goto A;
                }
                mycards.push_back(c1);
                oppcards.push_back(c1);
                for (auto& s2 : suits) {
                    for (int r2 = 2; r2 < 15; ++r2) {
                        pair<int, char> c2 = { r2, s2 };
                        pair<int, vector<int>> myhand, opphand;
                        for (auto& c : mycards) {
                            if (c == c2)
                                goto B;
                        }
                        for (auto& c : oppcards) {
                            if (c == c2)
                                goto B;
                        }
                        mycards.push_back(c2);
                        oppcards.push_back(c2);
                        myhand = max_hand(mycards);
                        opphand = max_hand(oppcards);
                        ++all;
                        if (myhand > opphand) ++win;

                        mycards.pop_back();
                        oppcards.pop_back();

                        B: continue;
                    }
                }

                mycards.pop_back();
                oppcards.pop_back();

                A: continue;
            }
        }
        cout << win / (double)all << '\n';
    }

    return 0;
}



Measured memory_bytes: 3220