#include <bits/stdc++.h>
using namespace std;
bool v[6];
int a[100009][6], maxx = -1, t;
long long m = 1e9 + 7;
struct pi {
  long long ah[60][60];
};
pi multi(pi x, pi y) {
  pi z;
  for (int i = 1; i <= t; i++) {
    for (int j = 1; j <= t; j++) {
      z.ah[i][j] = 0;
      for (int k = 1; k <= t; k++)
        z.ah[i][j] = (z.ah[i][j] % m + x.ah[i][k] % m * y.ah[k][j] % m) % m;
      z.ah[i][j] %= m;
    }
  }
  return z;
}
pi quimul(pi x, long long int n) {
  pi an;
  for (int i = 1; i <= t; i++) an.ah[i][i] = 1;
  for (; n; n >>= 1) {
    if (n & 1) an = multi(an, x);
    x = multi(x, x);
  }
  return an;
}
int main() {
  long long n;
  int x, v, p[600], zh[90][90];
  char c = 'a', u;
  for (int i = 1; i <= 52; i++)
    for (int j = 1; j <= 52; j++) zh[i][j] = 1;
  for (int i = 1; i <= 26; i++) p[(int)c + i - 1] = i;
  c = 'A';
  for (int i = 27; i <= 52; i++) p[(int)c + i - 27] = i;
  cin >> n >> t >> v;
  for (int i = 0; i < v; i++) {
    scanf(" %c %c", &c, &u);
    zh[p[(int)c]][p[(int)u]] = 0;
  }
  pi ans;
  for (int i = 1; i <= t; i++)
    for (int j = 1; j <= t; j++) ans.ah[i][j] = zh[i][j];
  ans = quimul(ans, n - 1);
  long long int pp = 0;
  for (int i = 1; i <= t; i++)
    for (int j = 1; j <= t; j++) pp = (pp + ans.ah[i][j]) % m;
  cout << (pp + m) % m << endl;
}
