#include <bits/stdc++.h>
using namespace std;
struct Matrix {
  vector<vector<long long int> > d;
  long long int N;
  Matrix(const long long int& n) {
    N = n;
    d.resize(N);
    for (long long int i = 0; i < N; i++) d[i].resize(N);
  }
  Matrix operator*(const Matrix& m) const {
    Matrix a = Matrix(N);
    for (long long int i = 0; i < N; i++)
      for (long long int j = 0; j < N; j++)
        for (long long int k = 0; k < N; k++)
          a.d[i][j] =
              (a.d[i][j] + (d[i][k] * m.d[k][j]) % 1000000007) % 1000000007;
    return a;
  }
  vector<long long int> operator*(const vector<long long int>& vec) const {
    vector<long long int> ret(N);
    for (long long int i = 0; i < N; i++)
      for (long long int j = 0; j < N; j++)
        ret[i] = (ret[i] + (d[i][j] * vec[j]) % 1000000007) % 1000000007;
    return ret;
  }
  Matrix operator^(long long int p) const {
    assert(p >= 0);
    Matrix a = Matrix(N), b(*this);
    for (long long int i = 0; i < N; i++) a.d[i][i] = 1;
    while (p) {
      if (p & 1) a = a * b;
      b = b * b;
      p >>= 1;
    }
    return a;
  }
};
long long int powmod(long long int base, long long int pow) {
  long long int res = 1;
  while (pow) {
    if (pow % 2 != 0) res = (res * base) % 1000000007;
    base = (base * base) % 1000000007;
    pow /= 2;
  }
  return res;
}
inline long long int con(char ch) {
  if (ch >= 'a' and ch <= 'z')
    return ch - 97;
  else
    return ch - 65 + 26;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m, k;
  cin >> n >> m >> k;
  vector<long long int> g;
  for (long long int i = 0; i < m; i++) g.push_back(1);
  Matrix mm = Matrix(m);
  for (long long int i = 0; i < m; i++)
    for (long long int j = 0; j < m; j++) mm.d[i][j] = 1;
  for (long long int i = 0; i < k; i++) {
    char ch1, ch2;
    cin >> ch1 >> ch2;
    mm.d[con(ch2)][con(ch1)] = 0;
  }
  g = (mm ^ (n - 1)) * g;
  long long int sum = 0;
  for (auto term : g) sum = (sum + term) % 1000000007;
  cout << sum;
}
