fin = open("typing.in", 'r')
fout = open("typing.out", 'w')


n, m, l = map(int, fin.readline().split())
k = [float("inf") for i in range(n + 1)]
k[0] = 0
s = ' ' + fin.readline()
d = dict()

for i in range(m):
    cost, word = fin.readline().split()
    cost = int(cost)
    for ww in range(-4, 4):
        w = word[max(0, ww): min(len(word), ww + len(word))]
        if w not in d:
            d[w] = float("inf")
        d[w] = min(d[w], cost)
#for i in d.items():
    #print(i[0], i[1])

for i in range(1, n + 1):
    for j in range(1, i + 1):
        print(i, j)
        w = s[j:i + 1]
        if w in d:
            k[i] = min(k[i], k[j - 1] + d[w])
if k[-1] * 2 == k[-1]:
    k[-1] = -1
print(k[-1])
print(k[-1], file=fout)
fin.close()
fout.close()    