#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

const ll MOD = 1000000007;
//const ll MOD = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = 1;
        mint tmp = 1;
        while(t > 0) {
            if (t & 1) a *= tmp;
            tmp *= *this;
            t >>= 1;
        }

        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        return mint(*this) /= a;
    }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

typedef vector<mint> vmi;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int h, w; cin >> h >> w;
    vector<string> m(h);
    REP(i, h) cin >> m[i];

    vector<vi> cnt(h, vi(w, 0));

    // left - right
    REP(i, h) {
        int j = 0;
        int s = 0;
        while(j < w) {
            if (m[i][j] == '#') {
                for (int k = j - 1; k > -1 && m[i][k] != '#'; --k) {
                    cnt[i][k] += j;
                }
                s = j + 1;
            } else {
                cnt[i][j] -= s;
            }
            ++j;
        }

        for (int k = j - 1; k > -1 && m[i][k] != '#'; --k) {
            cnt[i][k] += j;
        }
    }

    // top
    REP(j, w) {
        int i = 0;
        int s = 0;
        while(i < h) {
            if (m[i][j] == '#') {
                for (int k = i - 1; k > -1 && m[k][j] != '#'; --k) {
                    cnt[k][j] += i;
                }
                s = i + 1;
            } else {
                cnt[i][j] -= s;
            }
            ++i;
        }

        for (int k = i - 1; k > -1 && m[k][j] != '#'; --k) {
            cnt[k][j] += i;
        }
    }

    ll all = 0;
    REP(i, h) REP(j, w) all += int(m[i][j] == '.');

    mint ans = 0;
    vmi t(all + 1, 1);
    FOR(i, 1, all + 1) t[i] = t[i - 1] * 2;

    REP(i, h) REP(j, w) {
        if (m[i][j] == '#') continue;
        int c = cnt[i][j] - 1;
        ans += t[all] - t[all - c];
    }

    print(ans);
}
//              .-""""-.
//                        / j      \
//                       :.d;       ;
//                       $P        :
//            .m._       $$         :
//           dSMMSSSss.__$b.    __ :
//          :MMSMMSSSMMMSS$$b  $P ;
//          SMMMSMMSMMMSSS$$$$     :b
//         dSMMMSMMMMMMSSMM$$b.dP SSb.
//        dSMMMMMMMMMMSSMMPT$$=-. /TSSSS.
//       :SMMMSMMMMMMMSMMP  `b_.'  MMMMSS.
//       SMMMMMSMMMMMMMMM \  .'\    :SMMMSSS.
//      dSMSSMMMSMMMMMMMM  \/\_/; .'SSMMMMSSSm
//     dSMMMMSMMSMMMMMMMM    :.;'" :SSMMMMSSMM;
//   .MMSSSSSMSSMMMMMMMM;    :.;   MMSMMMMSMMM;
//  dMSSMMSSSSSSSMMMMMMM;    ;.;   MMMMMMMSMMM
// :MMMSSSSMMMSSP^TMMMMM     ;.;   MMMMMMMMMMM
// MMMSMMMMSSSSP   `MMMM     ;.;   :MMMMMMMMM;
// "TMMMMMMMMMM      TM;    :`.:    MMMMMMMMM;
//    )MMMMMMM;     _/\    :`.:    :MMMMMMMM
//   dSS$$MMMb.  |._\\   :`.:     MMMMMMMM
//   T$S$$$$$$$$$m;O\\"-;`.:_.-  MMMMMMM;
//  :$$$$$$$$$$$$$$b_l./\ ;`.:    mMMSSMMM;
//  :$$$$$$$$$$$$$$$$$$$./\;`.:  .$MSMMMMMM
//   $$$$$$$$$$$$$$$$$$$$. \`.:.$$$SMSSSMMM;
//   $$$$$$$$$$$$$$$$$$$$$. \.:$$$$SSMMMMMMM
//   :$$$$$$$$$$$$$$$$$$$$$.//.:$$$SSSSSSSMM;
//   :$$$$$$$$$$$$$$$$$$$$$$.`.:$SSSSSSSMMMP
//    $$$$$$$$$;"^J "^$$$$;.`.$P  `SSSMMMM
//    :$$$$$$$$$       :$$$;.`.P'..   TMMM$b
//    :$$$$$$$$$;      $$$$;.`/ c^'   d$$$$S;
//    $$$$S$$$$;      '^^^:_dg:___.$$$$$SSS
//    $$$SS$$$$;            $$$$$$$$$$$$$SSS;
//   :$$SSSS$$$$            : $$$$$$$$$$$$SSS
//   :P"TSSSS$$$            ; $$$$$$$$$$$$SSS;
//   j    `SSSSS$           :  :$$$$$$$$$$$$SS$
//  :       "^S^'           :   $$$$$$$$$$$$S$;
//  ;.____.-;"               "--^$$$$$$$$$$$$P
//  '-....-"  bug                  ""^^T$$$P"





#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define ss second
#define ff first
#define pll pair<ll,ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define mod 1000000007
#define sp " "
#define w(x) ll x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define re(i, j) fo(i, 0, j, 1)
#define pi 3.1415926535897932384626433832795
#define all(cont) cont.begin(), cont.end()
#define countbit(x) __builtin_popcount(x)
#define mod 1000000007
#define lo lower_bound
#define de(n) ll n;cin>>n;
#define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}
#define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}
#define deb(x) cout<<#x<<"="<<x<<endl;
#define tr(it,a) for(auto it=a.begin();it!=a.end();it++)
#define nl cout<<endl;

using namespace std;
//KnightMareVoid

ll power(ll x,ll y,ll mad){
    ll p=mad;
    ll res =1;
    x=x%p;
    while(y>0){
        if(y&1){
            res=(res*x)%p;
        }
            y=y>>1;
            x=(x*x)%p;
        }
        return res;

    
}

int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
  ll a,b,c;
  cin>>a>>b>>c;
  a%=10;
  if(a==5||a==6||a==1){
      cout<<a<<endl;
      return 0;
  }
  if(a==2 || a==8){
      ll k=power(b,c,4);
      if(k==0){
          cout<<6<<endl;
      }
      else if(k==1){
          cout<<(6*a)%10<<endl;
      }
      else if(k==2){
          cout<<(6*a*a)%10<<endl;

      }
      else{
          cout<<(6*a*a*a)%10<<endl;
      }

      
  }
  else if(a==7 || a==3){
      ll k=power(b,c,4);
         if(k==0){
          cout<<1<<endl;
      }
      else if(k==1){
          cout<<(1*a)%10<<endl;
      }
      else if(k==2){
          cout<<(1*a*a)%10<<endl;

      }
      else{
          cout<<(1*a*a*a)%10<<endl;
      }
  }
  else if(a==4){
         ll k=power(b,c,2);
         if(k==0){
          cout<<6<<endl;
      }
      else if(k==1){
          cout<<(6*a)%10<<endl;
      }
     
    
  }
  else if(a==0){
      cout<<0<<endl;
  }
  else if(a==9){
           ll k=power(b,c,2);
         if(k==0){
          cout<<1<<endl;
      }
      else if(k==1){
          cout<<(1*a)%10<<endl;
      }

  }



    return 0;
}
