#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    while (n--) {
        int cntA, cntB;
        int a[5] = {0}; 
        int b[5] = {0}; 

        cin >> cntA;
        for (int i = 0; i < cntA; i++) {
            int shape;
            cin >> shape;
            a[shape]++;
        }

        cin >> cntB;
        for (int i = 0; i < cntB; i++) {
            int shape;
            cin >> shape;
            b[shape]++;
        }

        if (a[4] != b[4]) {
            cout << (a[4] > b[4] ? 'A' : 'B') << '\n';
        } else if (a[3] != b[3]) {
            cout << (a[3] > b[3] ? 'A' : 'B') << '\n';
        } else if (a[2] != b[2]) {
            cout << (a[2] > b[2] ? 'A' : 'B') << '\n';
        } else if (a[1] != b[1]) {
            cout << (a[1] > b[1] ? 'A' : 'B') << '\n';
        } else {
            cout << 'D' << '\n';
        }
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: