#include <stdio.h>

int letter_selecter(char *input, char *reg);
/**
 * definition of the expression
 * [.] - any charater
 * [*] - precceding charachter 0 or more
 * for all the other characters - exactly the same character
 */

int main(int argc, char** argv)
{
    char input[128];
    char reg[128];
    int success = 0;

    while(1)
    {
        scanf("%s",input);
        if(*input == '-')
        {
            break;
        }
        scanf("%s",reg);
            
       
        success = letter_selecter( input, reg);
    
        if(success == 1)
        {
            printf("(%s, %s) matched\n", input, reg);
        }
        else if(success == 0)
        {
            printf("(%s, %s) not matched\n", input, reg);
        }
        else
        {
            printf("wrong expression\n");
        }
    }

    return 0;
}

/** here the reg should be starting from non '*' */
int letter_selecter(char *input, char *reg)
{
    int i = 0;
    int success = 0;

    if( *reg == '*')
    {
        return -1; /* this is at an error */
    }

    if( *reg == '\0')
    {
        return 0;  /* no need to contineu */
    }


    while(*reg != '\0' && *input != '\0')
    {
        if( *(reg+1) != '*') /* then just advance everything */
        {
            if( *reg != '.' && *reg != *input)  /* mean it is a known character */
            {
                success = 0; /* wrong match */
                break;
            }
            reg ++;
            input ++;
            continue;
        }
        else /* otherwise just take care letter one by one */
        {
            /** now the next char is a * */
            success = letter_selecter(input, reg + 2);
            if( success == 1)
            {
                break; /* what else we want;) */
            }
            else if(success == 0 )
            {
                /* just match off current character -advance only if matches */
                if( *reg != '.' && *reg != *input)  /* mean it is a known character */
                {
                    success = 0; /* wrong match */
                    break;
                }
                input ++;
                continue;
            }
        }
    }

    if(*input == '\0' && *(reg +1) == '*' && *(reg+2) == '\0')
    {
        /* blank input will be matched by any x* */
        success = 1;
    }

    if( *reg == '\0' && *input == '\0')
    {
        success = 1;
    } 
    return success;
}
