#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int mod = 1000000007;
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    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, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w;
    cin >> h >> w;
    vector<string> f(h);
    rep(i,h) cin >> f[i];
    vector<vector<int>> sum(h, vector<int>(w));
    rep(i,h){
        int tmp, l;
        l = -1; tmp = 0;
        rep(j,w){
            if(f[i][j] == '.'){
                if(l == -1) l = j;
                tmp++;
            }
            else{
                if(l == -1) continue;
                for(int k = l; k < j; k++){
                    sum[i][k] += tmp;
                }
                tmp = 0;
                l = -1;
            }
        }
        if(l != -1){
            for(int k = l; k <= w-1; k++) sum[i][k] = tmp;
        }
    }

    /*rep(i,h){
        rep(j,w) cout << sum[i][j] << ' ';
        cout << endl; 
    }*/

    rep(j,w){
        int tmp, l;
        l = -1, tmp = 0;
        rep(i,h){
            if(f[i][j] == '.'){
                if(l == -1) l = i;
                tmp++;
            }
            else{
                if(l == -1) continue;
                for(int k = l; k < i; k++){
                    sum[k][j] += tmp;
                }
                //if(j == 0) cout << tmp << ' ' << l  << ' ' << endl;
                tmp = 0;
                l = -1;
            }
        }
        if(l != -1){
            for(int k = l; k < h; k++){
                sum[k][j] += tmp;
            }
        }
    }
/*
    rep(i,h){
        rep(j,w) cout << sum[i][j] << ' ';
        cout << endl; 
    }
*/
    vector<mint> p(4000001);
    p[0] = 1;
    rep(i,4000000){
        p[i+1] = p[i];
        p[i+1] *= 2;
    }

    int t = 0;
    rep(i,h) rep(j,w) if(f[i][j] == '.') t++;
    mint ans = 0;
    rep(i,h) rep(j,w) if(sum[i][j] > 0) sum[i][j]--;
/*
    rep(i,h){
        rep(j,w) cout << sum[i][j] << ' ';
        cout << endl; 
    }
*/
    rep(i,h) rep(j,w){
        if(sum[i][j] > 0){
            mint tmp = 0;
            tmp += p[sum[i][j]];
            tmp -= 1;
            tmp *= p[t-sum[i][j]];
            ans += tmp;
        }
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;

int main() {
    //入力
    int n,m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i,m) cin >> a[i] >> b[i];
    int k;
    cin >> k;
    vector<int> c(k), d(k);
    rep(i,k) cin >> c[i] >> d[i];
    
    //出力
    int ans = 0;
    //2^kパターんを2進数で表現
    int k2 = 1<<k;
    rep(s,k2){ //条件全パターん網羅
        //入れる皿を用意
        vector<int> dish(n+1);
        //該当する皿にボールを追加
        rep(i,k){
            //右シフトして入れる場所にインクリメント
            if(s>>i&1) dish[d[i]]++;
            else dish[c[i]]++;
        }
        //条件を満たす皿の個数を数える
        //満たす個数
        int now = 0;
        rep(i,m){
            //条件の皿はa[i]とb[i]
            if (dish[a[i]] == 0) continue;
            if (dish[b[i]] == 0) continue;
            //上記以外なら増やす
            now++;
        }
        //現在の入れる皿と今までの最大値
        ans = max(ans, now);
    }
    cout << ans << endl;
    return 0;
}