#include <iostream>
#include <string>

using namespace std;

bool judgeSize(string str)
{
    int size = str.size();
    if (size < 8 || size>16)
        return false;
    return true;
}

int isA(string str)
{
    for (auto &c : str)
    {
        if (c >= 'A' && c <= 'Z')
            return 1;
    }
    return 0;
}
int isa(string str)
{
    for (auto &c : str)
    {
        if (c >= 'a' && c <= 'z')
            return 1;
    }
    return 0;
}
int is0(string str)
{
    for (auto &c : str)
    {
        if (c >= '0' && c <= '9')
            return 1;
    }
    return 0;
}
int isOther(string str)
{
    for (auto &c : str)
    {
        if (c == '~' || c == '!' || c == '@' || c == '#' || c == '$' || c == '%' || c == '^')
            return 1;

    }
    return 0;
}
int main()
{
    int M;
    string str;
    while (cin >> M)
    {
        while (M--)
        {
            cin >> str;
            if (judgeSize(str))
            {
                int judge = isA(str) + isa(str) + is0(str) + isOther(str);
                if (judge >= 3)
                {
                    cout << "YES" << endl;
                }
                else
                {
                    cout << "NO" << endl;
                }
            }
            else
            {
                cout << "NO" << endl;
            }
        }
    }
}