#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>
#include<functional>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
#define debug(output) cout<<#output<<"= "<<output<<endl
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
template<class T>
class SegTree{
    int n;
    vector<T> node;
    T e;
    function<T(T,T)> operation;
    function<T(T,T)> update;
    public:
    SegTree(int _n,T _e,function<T(T,T)> _operation,function<T(T,T)> _update):n(_n),e(_e),operation(_operation),update(_update){node.resize(n*2,e);}
    void change(int i,T x){
        i+=n;
        node[i]=update(node[i],x);
        while(i>1){
            i>>=1;
            node[i]=operation(node[i<<1|0],node[i<<1|1]);
        }
    }
    T get(int l,int r){
        T a=e;
        T b=e;
        l+=n;r+=n;
        while(l<r){
            if(l&1)a=operation(a,node[l++]);
            if(r&1)b=operation(node[--r],b);
            l>>=1;r>>=1;
        }
        return operation(a,b);
    }
    void input(vector<T>& _input){
        for(int i=0;i<n;++i){
            change(i,_input[i]);
        }
    }
};
signed main(){
  int h,w,m;cin>>h>>w>>m;
  vector<vector<int>> r(h+1);
  rep(i,m){
      int x,y;cin>>y>>x;
      r[y].push_back(x);
  }
  rep1(i,h){
      r[i].push_back(w+1);
      sort(r[i].begin(),r[i].end());
  }
  int lim=h+1;
  rep1(i,h){
      if(r[i].size()>0){
          if(r[i][0]==1){
              lim=i;
              break;
          }
      }
  }
  auto op=[](int a,int b){return a+b;};
  SegTree<int> tree(h+w+1,0,op,op);
  lint res=0;
  priority_queue<P> que;
  for(int i=1;i<lim;++i){
      if(r[i].size()>0){
          res+=r[i][0]-1;
          que.push({r[i][0],i});
      }
  }
  vector<vector<int>> a(w+5);
  rep1(i,h){
      for(auto& val:r[i]){
          a[val].push_back(i);
      }
  }
  rep1(i,w){
      a[i].push_back(h+1);
      sort(a[i].begin(),a[i].end());
  }
  lim=r[1][0];
  que.push({0,0});
  for(int i=lim-1;i>0;--i){
      while(que.top().first>=i){
          tree.change(que.top().second,1);que.pop();
      }
      res+=a[i][0]-1-tree.get(1,a[i][0]);
  }
  cout<<res<<"\n";
  return 0;
}
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 2e3 + 7;
const int mod = 1e9 + 7;

ll p[maxn * maxn];
char s[maxn][maxn];
int U[maxn][maxn],D[maxn][maxn],L[maxn][maxn],R[maxn][maxn];
int n,m;

void init() {
    p[0] = 1;
    for(int i = 1;i <= maxn * maxn - 2;i++) {
        p[i] = p[i - 1] * 2 % mod;
    }
    memset(U,0x3f,sizeof(U));
    for(int i = 1;i <= n;i++) {
        for(int j = 1;j <= m;j++) {
            if(s[i][j] == '.') {
                U[i][j] = i;
                U[i][j] = min(U[i][j],U[i - 1][j]);
            }
        }
    }
    
    for(int i = n;i >= 1;i--) {
        for(int j = 1;j <= m;j++) {
            if(s[i][j] == '.') {
                D[i][j] = i;
                D[i][j] = max(D[i][j],D[i + 1][j]);
            }
        }
    }
    
    memset(L,0x3f,sizeof(L));
    for(int j = 1;j <= m;j++) {
        for(int i = 1;i <= n;i++) {
            if(s[i][j] == '.') {
                L[i][j] = j;
                L[i][j] = min(L[i][j],L[i][j - 1]);
            }
        }
    }
    
    for(int j = m;j >= 1;j--) {
        for(int i = 1;i <= n;i++) {
            if(s[i][j] == '.') {
                R[i][j] = j;
                R[i][j] = max(R[i][j],R[i][j + 1]);
            }
        }
    }
}

int main() {
    scanf("%d%d",&n,&m);
    int cnt = 0;
    for(int i = 1;i <= n;i++) {
        scanf("%s",s[i] + 1);
        for(int j = 1;j <= m;j++) {
            if(s[i][j] == '.') {
                cnt++;
            }
        }
    }
    init();
    ll ans = 0;
    for(int i = 1;i <= n;i++) {
        for(int j = 1;j <= m;j++) {
            if(s[i][j] == '.') {
                int num = D[i][j] - U[i][j] + R[i][j] - L[i][j] + 1;
//                printf("%d %d %d %d\n",L[i][j],R[i][j],U[i][j],D[i][j]);
//                printf("FUCK %d\n",num);
                ans = (ans + p[cnt - num] * (p[num] - 1) % mod + mod) % mod;
            }
        }
    }
    printf("%lld\n",((ans + mod) % mod));
    return 0;
}
