#include <cstdio>
#include <cstring>
using namespace std;
int g[10] = {16, 7, 8, 1, 1, 2, 3};

int calc()
{
    char s[3];
    int n, ret = 0, v[10];
    memset(v, 0, sizeof(v));

    scanf("%d", &n);
    while (n--)
    {
        scanf("%s", s);
        int id = s[0] - 'A';
        ret += g[id];
        v[id] = 1;
    }

    if ((v[1] == 0 || v[2] == 0) && ret != 1)
        ret--;
    return ret;
}

int main ()
{
    int T;
    scanf("%d", &T);
    while (T--)
    {
        int l = calc(),r = calc();
        printf("%s\n",l==r?"tie":( l > r ? "red" : "black"));
    }
    return 0;
}
