s = eval(input())

t = eval(input())

l_s = len(s)

l_t = len(t)



s2 = s + s

l_s2 = len(s2)



next_idx_1 = [[l_s2] * 26 for i in range(l_s2+1)]



for i in reversed(list(range(l_s2))):

    for j in range(26):

        next_idx_1[i][j] = next_idx_1[i+1][j]

    next_idx_1[i][ord(s2[i]) - ord("a")] = i



next_idx_2 = [[l_s2] * 26 for i in range(l_s2)]



for i in reversed(list(range(1, l_s2))):

    for j in range(26):

        next_idx_2[i-1][j] = next_idx_2[i][j]

    next_idx_2[i-1][ord(s2[i]) - ord("a")] = i



cur_idx = 0

for i in range(l_t):

    if i == 0:

        idx = next_idx_1[cur_idx%l_s][ord(t[i]) - ord("a")]



    else:

        idx = next_idx_2[cur_idx%l_s][ord(t[i]) - ord("a")]



    if idx == l_s2:

        print("-1")

        exit()



    cur_idx += idx - (cur_idx % l_s)

    

print((cur_idx+1))
s = eval(input())

t = eval(input())

l_s = len(s)

l_t = len(t)



s2 = s + s

l_s2 = len(s2)



next_idx = [[l_s2] * 26 for i in range(l_s2)]



for i in reversed(list(range(1, l_s2))):

    for j in range(26):

        next_idx[i-1][j] = next_idx[i][j]

    next_idx[i-1][ord(s2[i]) - ord("a")] = i



cur_idx = 0

for i in range(l_t):

    if i == 0:

        flg = False

        for j in range(l_s):

            if t[i] == s[j]:

                cur_idx += j

                flg = True

                break

        if flg:

            continue

        else:

            print("-1")

            exit()



    else:

        idx = next_idx[cur_idx%l_s][ord(t[i]) - ord("a")]



    if idx == l_s2:

        print("-1")

        exit()



    cur_idx += idx - (cur_idx % l_s)

    

print((cur_idx+1))
s = eval(input())
t = eval(input())
l_s = len(s)
l_t = len(t)
s2 = s + s
l_s2 = len(s2)
next_idx_1 = [[l_s2] * 26 for i in range(l_s2 + 1)]
for i in reversed(list(range(l_s2))):
    for j in range(26):
        next_idx_1[i][j] = next_idx_1[i + 1][j]
    next_idx_1[i][ord(s2[i]) - ord("a")] = i
next_idx_2 = [[l_s2] * 26 for i in range(l_s2)]
for i in reversed(list(range(1, l_s2))):
    for j in range(26):
        next_idx_2[i - 1][j] = next_idx_2[i][j]
    next_idx_2[i - 1][ord(s2[i]) - ord("a")] = i
cur_idx = 0
for i in range(l_t):
    if i == 0:
        idx = next_idx_1[cur_idx % l_s][ord(t[i]) - ord("a")]
    else:
        idx = next_idx_2[cur_idx % l_s][ord(t[i]) - ord("a")]
    if idx == l_s2:
        print("-1")
        exit()
    cur_idx += idx - (cur_idx % l_s)
print((cur_idx + 1))

s = eval(input())
t = eval(input())
l_s = len(s)
l_t = len(t)
s2 = s + s
l_s2 = len(s2)
next_idx = [[l_s2] * 26 for i in range(l_s2)]
for i in reversed(list(range(1, l_s2))):
    for j in range(26):
        next_idx[i - 1][j] = next_idx[i][j]
    next_idx[i - 1][ord(s2[i]) - ord("a")] = i
cur_idx = 0
for i in range(l_t):
    if i == 0:
        flg = False
        for j in range(l_s):
            if t[i] == s[j]:
                cur_idx += j
                flg = True
                break
        if flg:
            continue
        else:
            print("-1")
            exit()
    else:
        idx = next_idx[cur_idx % l_s][ord(t[i]) - ord("a")]
    if idx == l_s2:
        print("-1")
        exit()
    cur_idx += idx - (cur_idx % l_s)
print((cur_idx + 1))

-next_idx_1 = [[l_s2] * 26 for i in range(l_s2 + 1)] -for i in reversed(list(range(l_s2))): -    for j in range(26): -        next_idx_1[i][j] = next_idx_1[i + 1][j] -    next_idx_1[i][ord(s2[i]) - ord("a")] = i -next_idx_2 = [[l_s2] * 26 for i in range(l_s2)] +next_idx = [[l_s2] * 26 for i in range(l_s2)] -        next_idx_2[i - 1][j] = next_idx_2[i][j] -    next_idx_2[i - 1][ord(s2[i]) - ord("a")] = i +        next_idx[i - 1][j] = next_idx[i][j] +    next_idx[i - 1][ord(s2[i]) - ord("a")] = i -        idx = next_idx_1[cur_idx % l_s][ord(t[i]) - ord("a")] +        flg = False +        for j in range(l_s): +            if t[i] == s[j]: +                cur_idx += j +                flg = True +                break +        if flg: +            continue +        else: +            print("-1") +            exit() -        idx = next_idx_2[cur_idx % l_s][ord(t[i]) - ord("a")] +        idx = next_idx[cur_idx % l_s][ord(t[i]) - ord("a")]