#include <bits/stdc++.h>   using namespace std;   class classcomp {    public:     bool operator()(const int &l, const int &r) const { return l < r; }   };   long long mod = 1000000007;   void matrixmul(int p, int q, int r, long long *a, long long *b, long long *c) {     int i, j, k;     for (i = 0; i < p; i++) {       for (j = 0; j < r; j++) {         c[i * r + j] = 0;         for (k = 0; k < q; k++)           c[i * r + j] = (c[i * r + j] + a[i * q + k] * b[k * r + j]) % mod;       }     }   }   void exp(int q, long long *a, long long *c, long long n) {     int i, j;     if (n == 0) {       for (i = 0; i < q; i++) {         for (j = 0; j < q; j++) c[i * q + j] = 0;         c[i * q + i] = 1;       }       return;     }     long long x[q * q];     exp(q, a, x, n / 2);     matrixmul(q, q, q, x, x, c);     if (n % 2 == 1) {       memcpy(x, c, sizeof(x));       matrixmul(q, q, q, a, x, c);     }     return;   }   int main() {     long long n, m, k;     cin >> n >> m >> k;     long long a[m * m];     int i, j, l;     char s[10];     for (i = 0; i < m; i++)       for (j = 0; j < m; j++) a[i * m + j] = 1;     for (i = 0; i < k; i++) {       scanf( %s , s);       if ( a  <= s[0] && s[0] <=  z )         j = s[0] -  a ;       else         j = s[0] -  A  + 26;       if ( a  <= s[1] && s[1] <=  z )         l = s[1] -  a ;       else         l = s[1] -  A  + 26;       a[l * m + j] = 0;     }     long long ans[m * m];     exp(m, a, ans, n - 1);     long long ret = 0;     for (i = 0; i < m; i++)       for (j = 0; j < m; j++) {         ret = (ret + ans[i * m + j]) % mod;       }     cout << ret << endl;     return 0;   }   