Problem: In Takaha-shi, the capital of Republic of AtCoder, there are N roads extending east and west, and M roads extending north and south. There are no other roads. The i-th east-west road from the north and the j-th north-south road from the west cross at the intersection (i, j). Two east-west roads do not cross, nor do two north-south roads. The distance between two adjacent roads in the same direction is 1.

Each road is one-way; one can only walk in one direction. The permitted direction for each road is described by a string S of length N and a string T of length M, as follows:

* If the i-th character in S is `W`, one can only walk westward along the i-th east-west road from the north;
* If the i-th character in S is `E`, one can only walk eastward along the i-th east-west road from the north;
* If the i-th character in T is `N`, one can only walk northward along the i-th north-south road from the west;
* If the i-th character in T is `S`, one can only walk southward along the i-th south-west road from the west.



Process the following Q queries:

* In the i-th query, a_i, b_i, c_i and d_i are given. What is the minimum distance to travel to reach the intersection (c_i, d_i) from the intersection (a_i, b_i) by walking along the roads?

Constraints

* 2 \leq N \leq 100000
* 2 \leq M \leq 100000
* 2 \leq Q \leq 200000
* |S| = N
* S consists of `W` and `E`.
* |T| = M
* T consists of `N` and `S`.
* 1 \leq a_i \leq N
* 1 \leq b_i \leq M
* 1 \leq c_i \leq N
* 1 \leq d_i \leq M
* (a_i, b_i) \neq (c_i, d_i)

Input

Input is given from Standard Input in the following format:


N M Q
S
T
a_1 b_1 c_1 d_1
a_2 b_2 c_2 d_2
:
a_Q b_Q c_Q d_Q


Output

In the i-th line, print the response to the i-th query. If the intersection (c_i, d_i) cannot be reached from the intersection (a_i, b_i) by walking along the roads, print `-1` instead.

Examples

Input

4 5 4
EEWW
NSNNS
4 1 1 4
1 3 1 2
4 2 3 2
3 3 3 5


Output

6
11
5
4


Input

3 3 2
EEE
SSS
1 1 3 3
3 3 1 1


Output

4
-1


Input

9 7 10
EEEEEWEWW
NSSSNSN
4 6 9 2
3 7 6 7
7 5 3 5
1 1 8 1
4 3 5 4
7 4 6 4
2 5 8 6
6 6 2 7
2 4 7 5
7 2 9 7


Output

9
-1
4
9
2
3
7
7
6
-1

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  int n,m,q;
  cin>>n>>m>>q;
  string s,t;
  cin>>s>>t;
  
  const int INF = 1e9;
  vector<int> vw,ve,vn,vs;
  vw.emplace_back(-INF);
  ve.emplace_back(-INF);
  vn.emplace_back(-INF);
  vs.emplace_back(-INF);  
  for(int i=0;i<n;i++){
    if(s[i]=='W') vw.emplace_back(i);
    if(s[i]=='E') ve.emplace_back(i);
  }
  for(int i=0;i<m;i++){
    if(t[i]=='N') vn.emplace_back(i);
    if(t[i]=='S') vs.emplace_back(i);
  }  
  vw.emplace_back(+INF);
  ve.emplace_back(+INF);
  vn.emplace_back(+INF);
  vs.emplace_back(+INF);

  vector<int> pnu(m),psu(m);
  vector<int> pnl(m),psl(m);
  for(int j=0;j<m;j++){    
    pnu[j]=*--upper_bound(vn.begin(),vn.end(),j);
    psu[j]=*--upper_bound(vs.begin(),vs.end(),j);    
    pnl[j]=*lower_bound(vn.begin(),vn.end(),j);
    psl[j]=*lower_bound(vs.begin(),vs.end(),j);
  }
  
  vector<int> pwu(n),peu(n);
  vector<int> pwl(n),pel(n);
  for(int i=0;i<n;i++){    
    pwu[i]=*--upper_bound(vw.begin(),vw.end(),i);
    peu[i]=*--upper_bound(ve.begin(),ve.end(),i);    
    pwl[i]=*lower_bound(vw.begin(),vw.end(),i);
    pel[i]=*lower_bound(ve.begin(),ve.end(),i);
  }      
  
  for(int i=0;i<q;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;b--;c--;d--;

    using ll = long long;    
    auto T=[&](int y,int x,int step){return ((ll)y<<40)|((ll)x<<20)|(ll)step;};
    map<ll, int> dp;
    using P = pair<int, ll>;
    priority_queue<P, vector<P>, greater<P> > pq;
    dp[T(a,b,0)]=0;
    pq.emplace(dp[T(a,b,0)],T(a,b,0));

    int ans=INF;
    while(!pq.empty()){
      int sum=pq.top().first;
      ll st=pq.top().second;
      pq.pop();
      if(dp[st]<sum) continue;
      int y,x,step;
      y=(st>>40);
      x=(st>>20)^((ll)y<<20);
      step=st&((1<<20)-1);
      
      if(sum+abs(y-c)+abs(x-d)>=ans) continue;
      
      if((s[y]=='E'&&x<=d)||(s[y]=='W'&&x>=d))
        if((t[d]=='S'&&y<=c)||(t[d]=='N'&&y>=c))
          chmin(ans,sum+abs(y-c)+abs(x-d));
      
      if((t[x]=='S'&&y<=c)||(t[x]=='N'&&y>=c))
        if((s[c]=='E'&&x<=d)||(s[c]=='W'&&x>=d))
          chmin(ans,sum+abs(y-c)+abs(x-d));

      if(sum+abs(y-c)+abs(x-d)>=ans) continue;
      if(step>=3) continue;
      auto push=
        [&](int ny,int nx,int ns,int nd){
          if(abs(ny)==INF||abs(nx)==INF) return;
          if(ny==y&&nx==x) return;          
          if(dp.count(T(ny,nx,ns))&&dp[T(ny,nx,ns)]<=nd) return;
          dp[T(ny,nx,ns)]=nd;
          pq.emplace(nd,T(ny,nx,ns));
        };

      if(s[y]=='W'){
        for(int xx:{x,d}){
          // N           
          if(pnu[xx]<=x)
            push(y,pnu[xx],step+1,sum+abs(pnu[xx]-x));
          // S
          if(psu[xx]<=x)
            push(y,psu[xx],step+1,sum+abs(psu[xx]-x));
        }
      }else{
        for(int xx:{x,d}){
          // N           
          if(pnl[xx]>=x)
            push(y,pnl[xx],step+1,sum+abs(pnl[xx]-x));
          // S
          if(psl[xx]>=x)
            push(y,psl[xx],step+1,sum+abs(psl[xx]-x));
        }
      }
      if(t[x]=='N'){
        for(int yy:{y,c}){
          // W
          if(pwu[yy]<=y)
            push(pwu[yy],x,step+1,sum+abs(pwu[yy]-y));
          // E
          if(peu[yy]<=y)
            push(peu[yy],x,step+1,sum+abs(peu[yy]-y));
        }
      }else{        
        for(int yy:{y,c}){
          // W
          if(pwl[yy]>=y)
            push(pwl[yy],x,step+1,sum+abs(pwl[yy]-y));
          // E
          if(pel[yy]>=y)
            push(pel[yy],x,step+1,sum+abs(pel[yy]-y));
        }
      } 
    }
    if(ans==INF) ans=-1;
    cout<<ans<<"\n";
  }
  cout<<flush;
  return 0;
}