#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> operator*(vector<vector<long long>>& a,
                                    vector<vector<long long>>& b) {
  int n = a.size(), m = b.size(), p = a[0].size();
  vector<vector<long long>> c(n, vector<long long>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      c[i][j] = 0;
      for (int k = 0; k < p; k++) {
        c[i][j] += (a[i][k] * b[k][j]) % 1000000007;
        c[i][j] %= 1000000007;
      }
    }
  }
  return c;
}
vector<vector<long long>> operator^(vector<vector<long long>>& a, long long n) {
  if (n == 1) return a;
  vector<vector<long long>> c = a ^ (n / 2);
  c = c * c;
  if (n % 2) c = c * a;
  return c;
}
int chg(char c) {
  if (c >= 'a')
    return 1 + c - 'a';
  else
    return c - 'A' + 27;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  int m, k;
  cin >> n >> m >> k;
  vector<vector<long long>> mat(m + 2, vector<long long>(m + 2, 1));
  for (int i = 0; i < m + 2; i++) {
    mat[m + 1][i] = mat[i][0] = 0;
  }
  string x;
  for (int i = 0; i < k; i++) {
    cin >> x;
    mat[chg(x[0])][chg(x[1])] = 0;
  }
  mat = mat ^ (n + 1);
  cout << mat[0][m + 1] << endl;
  return 0;
}
