#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long MOD = 1000000007;
template <class T>
int getbit(T x, int pos) {
  return (x >> (pos - 1)) & 1;
}
template <class T>
void turn_on(T &x, int pos) {
  x = x | ((T)1 << (pos - 1));
}
template <class T>
void turn_off(T &x, int pos) {
  x = x & ~((T)1 << (pos - 1));
}
template <class T>
T sqr(T a) {
  return a * a;
}
struct matrix {
  int m, n;
  long long mtx[54][54];
  matrix() { memset(mtx, 0, sizeof(mtx)); }
  matrix(int M, int N) {
    memset(mtx, 0, sizeof(mtx));
    m = M;
    n = N;
  }
} x, y;
int m, k;
long long n;
matrix operator*(matrix a, matrix b) {
  matrix res(a.m, b.n);
  for (int k = 1; k <= a.n; ++k)
    for (int i = 1; i <= a.m; ++i)
      for (int j = 1; j <= b.n; ++j) {
        res.mtx[i][j] = (res.mtx[i][j] + a.mtx[i][k] * b.mtx[k][j]) % MOD;
      }
  return res;
}
matrix POW(matrix n, long long k) {
  if (k == 1) return n;
  matrix tmp = POW(n, k / 2);
  if (k % 2 == 0) return tmp * tmp;
  return tmp * tmp * n;
}
int getID(char x) {
  if (x <= 90) return x - 'A' + 27;
  return x - 'a' + 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k;
  x.m = x.n = y.m = m;
  y.n = 1;
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= m; ++j) x.mtx[i][j] = 1;
  for (int i = 1; i <= k; ++i) {
    char a, b;
    cin >> a >> b;
    x.mtx[getID(b)][getID(a)] = 0;
  }
  for (int i = 1; i <= m; ++i) y.mtx[i][1] = 1;
  if (n == 1) {
    cout << m;
    return 0;
  }
  x = POW(x, n - 1) * y;
  long long res = 0;
  for (int i = 1; i <= m; ++i) res = (res + x.mtx[i][1]) % MOD;
  cout << res;
}
