Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most *m* different nucleotides, numbered from 1 to *m*. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is *k*. 

The needs of gene research required information about the quantity of correct *n*-long chains of the Martian DNA. Your task is to write a program that will calculate this value.
The first line contains three space-separated integers *n*, *m*, *k* (1 ≤ *n* ≤ 10<sup class="upper-index">15</sup>, 1 ≤ *m* ≤ 52, 0 ≤ *k* ≤ *m*<sup class="upper-index">2</sup>).

Next *k* lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide.

The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z").

It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than *m*. Note that order is important in nucleotide pairs.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
'''
    Python3(PyPy3) Template for Programming-Contest.
'''

import typing
import sys


def input():
    return sys.stdin.readline().rstrip()


DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)]  # LDRU
mod = int(1e9 + 7)
inf = 1 << 64


class Matrix:
    def __init__(self, m: int, n: int):
        self.row = m
        self.column = n
        self.array = [[0]*(n) for _ in range(m)]

    @classmethod
    def given_array(cls, LIST: typing.List[typing.List[typing.Union[int, float]]]):
        try:
            column = len(LIST[0])
            row = len(LIST)
            res = Matrix(row, column)
            for i in range(row):
                for j in range(column):
                    res.array[i][j] = LIST[i][j]
            return res
        except:
            raise ValueError("error!")

    @classmethod
    def eye(cls, m: int):
        res = Matrix(m, m)
        for i in range(m):
            res.array[i][i] = 1
        return res

    def show(self):
        for i in range(self.row):
            print(*self.array[i])
        return True

    def get(self, i: int, j: int):
        assert 0 <= i < self.row and 0 <= j < self.column
        return self.array[i][j]

    def shape(self):
        return self.row, self.column

    def __add__(self, other):
        if not isinstance(other, Matrix):
            return self.__addval__(other)

        assert self.row == other.row and self.column == other.column
        res = Matrix(self.row, self.column)
        for i in range(self.row):
            for j in range(self.column):
                res.array[i][j] = self.array[i][j] + other.array[i][j]
        return res

    def __addval__(self, other):
        assert isinstance(other, int) or isinstance(other, float), "ValueError"
        res = Matrix(self.row, self.column)
        for i in range(self.row):
            for j in range(self.column):
                res.array[i][j] = self.array[i][j] + other
        return res

    def __sub__(self, other):
        if not isinstance(other, Matrix):
            assert isinstance(other, int) or isinstance(
                other, float), "ValueError"
            return self.__addval__(-other)

        assert self.row == other.row and self.column == other.column
        res = Matrix(self.row, self.column)
        for i in range(self.row):
            for j in range(self.column):
                res.array[i][j] = self.array[i][j] - other.array[i][j]
        return res

    def __mul__(self, other):
        if not isinstance(other, Matrix):
            return self.__mulval__(other)

        assert self.column == other.row

        res = Matrix(self.row, other.column)
        for i in range(self.row):
            for j in range(other.column):
                res.array[i][j] = sum(self.array[i][_]*other.array[_][j]
                                      for _ in range(self.column))
        return res

    def __mulval__(self, other):
        assert isinstance(other, int) or isinstance(other, float), "ValueError"
        res = Matrix(self.row, self.column)
        for i in range(self.row):
            for j in range(self.column):
                res.array[i][j] = self.array[i][j] * other
        return res

    def __pow__(self, ord: int):
        assert self.row == self.column
        assert isinstance(ord, int), "ValueError"
        if ord == 0:
            return self.eye(self.row)
        if ord == 1:
            return self
        res = self.__pow__(ord >> 1)
        if ord % 2 == 0:
            return res.__mul__(res)
        return self.__mul__(self.__pow__(ord - 1))

    def powMod(self, ord: int, MODULO: int):
        assert self.row == self.column
        assert isinstance(ord, int), "ValueError"
        if ord == 0:
            return self.eye(self.row)
        if ord == 1:
            return self
        res = self.powMod(ord >> 1, MODULO)
        res *= res
        res %= MODULO
        if ord % 2 == 0:
            return res
        return (res * self) % MODULO

    def __mod__(self, modulo: int):
        res = Matrix(self.row, self.column)
        for i in range(self.row):
            for j in range(self.column):
                res.array[i][j] = self.array[i][j] % modulo
        return res

    def __eq__(self, other):
        if self.row != other.row or self.column != other.column:
            return False
        for i in range(self.row):
            for j in range(self.column):
                if self.array[i][j] != other.array[i][j]:
                    return False
        return True

    def __radd__(self, other):
        return __add__(other, self)

    def __rsub__(self, other):
        return __sub__(other, self)

    def __rmul__(self, other):
        return __mul__(other, self)

    def T(self):
        res = Matrix(self.column, self.row)
        for i in range(self.row):
            for j in range(self.column):
                res.array[j][i] = self.array[i][j]
        return res


def char_to_int(s: str) -> int:
    if ord('a') <= ord(s) <= ord('z'):
        return ord(s) - ord('a')
    else:
        return ord(s) - ord('A') + 26


def main():
    n, m, k = map(int, input().split())
    banned_pairs = set([])
    for i in range(k):
        _s = input()
        x, y = _s[0], _s[1]
        int_x, int_y = char_to_int(x), char_to_int(y)
        banned_pairs.add((int_x, int_y))

    M = Matrix(m, m)
    X = Matrix(m, 1)
    for i in range(m):
        X.array[i][0] += 1
    for i in range(m):
        for j in range(m):
            if (i, j) not in banned_pairs:
                M.array[j][i] += 1
    B = M.powMod(n - 1, mod) * X % mod
    ans = 0
    for i in range(m):
        ans += B.get(i, 0)
    print(ans % mod)
    return 0


if __name__ == "__main__":
    main()
