Mystic Message problem JavaScript

Здравейте ,може ли решение на тази задача ,че малко се затруднявам.

Mystic Message

The Master of the Mystic Arts is working on a very secret project in collaboration with a secret organization called The Prim****.

They communicate via convoluted messages that can either contain a hidden 4-letter keyword or not.

Since the Master of the Mystic Arts is very busy with his work, you are tasked with decoding the messages and informing him if a message contains the hidden word or not.

You will receive the original message, the 4-letter keyword that might be hidden inside the message and the rules by which you can search for the word.

Each rule consists of one letter from the 4-letter keyword, follow by four other letters it might be coded to.

I.e., the rule t:e,d,o,b means the letter t from the keyword can exist in the messages as either e, d, o or b.

The rules will be provided in the same order as the letters in the 4-letter keyword.

After you check for the hidden keyword in the message you must output the index of the element where the keyword starts, or -1 



Input

Exactly 6 lines:

the message

the keyword

first keyword letter rule

second keyword letter rule

third keyword letter rule

fourth keyword letter rule

Output

Exactly one line:

the index of the element the hidden word starts from - if the keyword is hidden in the message, or -1 otherwise

Input

gloprtbeinopl

gorn

g:a,b,c,d

o:e,f,g,h

r:i,j,k,l

n:m,n,o,p

Output

6

Explanation: You're looking for the hidden keyword gorn. g can be represented by either a, b, c or d, o can be represented by either e, f, g or h, etc. One valid representation of gorn is bein:

g -> b

o -> e

r -> i

n -> n

Since the message contains bein and bein starts at index 6, you print 6.

*/