#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n, m, q;
    cin>>n>>m>>q;
    string s, t;
    cin>>s>>t;
    vector<int> vw, ve, vn, vs;
    for(int i=0; i<n; i++){
        if(s[i]=='W') vw.push_back(i);
        else ve.push_back(i);
    }
    for(int i=0; i<m; i++){
        if(t[i]=='N') vn.push_back(i);
        else vs.push_back(i);
    }
    while(q--){
        int a, b, c, d;
        cin>>a>>b>>c>>d;
        a--; b--; c--; d--;
        int h[6], w[6];
        h[1]=min(a, c), h[4]=max(a, c), w[1]=min(b, d), w[4]=max(b, d);
        if(s[h[1]]=='W'){
            h[2]=upper_bound(ve.begin(), ve.end(), h[1])-ve.begin();
            if(h[2]-1>=0) h[0]=ve[h[2]-1];
            else h[0]=-1;
            if(h[2]<ve.size()) h[2]=ve[h[2]];
            else h[2]=-1;
            int k=upper_bound(vw.begin(), vw.end(), h[1])-vw.begin();
            if(k<vw.size()) h[3]=vw[k];
            else h[3]=-1;
            if(h[2]>=h[4]) h[2]=-1;
            if(h[3]>=h[4]) h[3]=-1;
        }else{
            h[2]=upper_bound(vw.begin(), vw.end(), h[1])-vw.begin();
            if(h[2]-1>=0) h[0]=vw[h[2]-1];
            else h[0]=-1;
            if(h[2]<vw.size()) h[2]=vw[h[2]];
            else h[2]=-1;
            int k=upper_bound(ve.begin(), ve.end(), h[1])-ve.begin();
            if(k<ve.size()) h[3]=ve[k];
            else h[3]=-1;
            if(h[2]>=h[4]) h[2]=-1;
            if(h[3]>=h[4]) h[3]=-1;
        }
        if(s[h[4]]=='W'){
            h[5]=upper_bound(ve.begin(), ve.end(), h[4])-ve.begin();
            if(h[5]<ve.size()) h[5]=ve[h[5]];
            else h[5]=-1;
        }else{
            h[5]=upper_bound(vw.begin(), vw.end(), h[4])-vw.begin();
            if(h[5]<vw.size()) h[5]=vw[h[5]];
            else h[5]=-1;
        }
        if(t[w[1]]=='N'){
            w[2]=upper_bound(vs.begin(), vs.end(), w[1])-vs.begin();
            if(w[2]-1>=0) w[0]=vs[w[2]-1];
            else w[0]=-1;
            if(w[2]<vs.size()) w[2]=vs[w[2]];
            else w[2]=-1;
            int k=upper_bound(vn.begin(), vn.end(), w[1])-vn.begin();
            if(k<vn.size()) w[3]=vn[k];
            else w[3]=-1;
            if(w[2]>=w[4]) w[2]=-1;
            if(w[3]>=w[4]) w[3]=-1;
        }else{
            w[2]=upper_bound(vn.begin(), vn.end(), w[1])-vn.begin();
            if(w[2]-1>=0) w[0]=vn[w[2]-1];
            else w[0]=-1;
            if(w[2]<vn.size()) w[2]=vn[w[2]];
            else w[2]=-1;
            int k=upper_bound(vs.begin(), vs.end(), w[1])-vs.begin();
            if(k<vs.size()) w[3]=vs[k];
            else w[3]=-1;
            if(w[2]>=w[4]) w[2]=-1;
            if(w[3]>=w[4]) w[3]=-1;
        }
        if(t[w[4]]=='N'){
            w[5]=upper_bound(vs.begin(), vs.end(), w[4])-vs.begin();
            if(w[5]<vs.size()) w[5]=vs[w[5]];
            else w[5]=-1;
        }else{
            w[5]=upper_bound(vn.begin(), vn.end(), w[4])-vn.begin();
            if(w[5]<vn.size()) w[5]=vn[w[5]];
            else w[5]=-1;
        }
        if(h[2]>h[3]) swap(h[2], h[3]);
        if(w[2]>w[3]) swap(w[2], w[3]);
        int h1[6], w1[6], cx=0, cy=0;
        for(int i=0; i<6; i++){
            if(h[i]==-1) continue;
            h1[cx++]=h[i];
        }
        for(int i=0; i<6; i++){
            if(w[i]==-1) continue;
            w1[cy++]=w[i];
        }
        int ax, ay, bx, by;
        for(int j=0; j<cx; j++){
            if(h1[j]==a) ax=j;
            if(h1[j]==c) bx=j;
        }
        for(int j=0; j<cy; j++){
            if(w1[j]==b) ay=j;
            if(w1[j]==d) by=j;
        }
        vector<P> g[36];
        for(int i=0; i<cx; i++){
            for(int j=0; j<cy-1; j++){
                if(w1[j]==w1[j+1]){
                    g[i*cy+j+1].push_back({w1[j+1]-w1[j], i*cy+j});
                    g[i*cy+j].push_back({w1[j+1]-w1[j], i*cy+j+1});
                }else if(s[h1[i]]=='W') g[i*cy+j+1].push_back({w1[j+1]-w1[j], i*cy+j});
                else g[i*cy+j].push_back({w1[j+1]-w1[j], i*cy+j+1});
            }
        }
        for(int j=0; j<cy; j++){
            for(int i=0; i<cx-1; i++){
                if(h1[i]==h1[i+1]){
                    g[(i+1)*cy+j].push_back({h1[i+1]-h1[i], i*cy+j});
                    g[i*cy+j].push_back({h1[i+1]-h1[i], (i+1)*cy+j});
                }else if(t[w1[j]]=='N') g[(i+1)*cy+j].push_back({h1[i+1]-h1[i], i*cy+j});
                else g[i*cy+j].push_back({h1[i+1]-h1[i], (i+1)*cy+j});
            }
        }
        priority_queue<P, vector<P>, greater<P>> que;
        int dist[36];
        const int INF=1e9+7;
        fill(dist, dist+36, INF);
        que.push({0, ax*cy+ay});
        dist[ax*cy+ay]=0;
        while(!que.empty()){
            P p=que.top(); que.pop();
            int x=p.second;
            if(dist[x]<p.first) continue;
            for(auto pr:g[x]){
                int y=pr.second, e=pr.first;
                if(dist[y]>dist[x]+e){
                    dist[y]=dist[x]+e;
                    que.push({dist[y], y});
                }
            }
        }
        if(dist[bx*cy+by]<INF) printf("%d\n", dist[bx*cy+by]);
        else printf("-1\n");
    }
	return 0;
}


Measured memory_bytes: 2748