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;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl

int n,m,q;
char s[125252];
int rw[125252], re[125252], lw[125252], le[125252];
char t[125252];
int rn[125252], rs[125252], ln[125252], ls[125252];

int main(){
	scanf("%d%d%d",&n,&m,&q);
	scanf("%s",s);
	scanf("%s",t);

	rw[n-1] = s[n-1]=='W' ? n-1 : -1;
	re[n-1] = s[n-1]=='E' ? n-1 : -1;
	FORR(i,0,n-1){
		rw[i] = s[i]=='W' ? i : rw[i+1];
		re[i] = s[i]=='E' ? i : re[i+1];
	}
	lw[0] = s[0]=='W' ? 0 : -1;
	le[0] = s[0]=='E' ? 0 : -1;
	FOR(i,1,n){
		lw[i] = s[i]=='W' ? i : lw[i-1];
		le[i] = s[i]=='E' ? i : le[i-1];
	}

	rn[m-1] = t[m-1]=='N' ? m-1 : -1;
	rs[m-1] = t[m-1]=='S' ? m-1 : -1;
	FORR(i,0,m-1){
		rn[i] = t[i]=='N' ? i : rn[i+1];
		rs[i] = t[i]=='S' ? i : rs[i+1];
	}
	ln[0] = t[0]=='N' ? 0 : -1;
	ls[0] = t[0]=='S' ? 0 : -1;
	FOR(i,1,m){
		ln[i] = t[i]=='N' ? i : ln[i-1];
		ls[i] = t[i]=='S' ? i : ls[i-1];
	}

	while(q--){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		--a;--b;--c;--d;
		set<pii> ys,xs;
		ys.insert(pii(a,s[a]));
		ys.insert(pii(c,s[c]));
		if(s[a]=='W'){
			int y;
			y=le[a];if(y!=-1)ys.insert(pii(y,s[y]));
			y=re[a];if(y!=-1)ys.insert(pii(y,s[y]));
		}else{
			int y;
			y=lw[a];if(y!=-1)ys.insert(pii(y,s[y]));
			y=rw[a];if(y!=-1)ys.insert(pii(y,s[y]));
		}
		if(s[c]=='W'){
			int y;
			y=le[c];if(y!=-1)ys.insert(pii(y,s[y]));
			y=re[c];if(y!=-1)ys.insert(pii(y,s[y]));
		}else{
			int y;
			y=lw[c];if(y!=-1)ys.insert(pii(y,s[y]));
			y=rw[c];if(y!=-1)ys.insert(pii(y,s[y]));
		}
		xs.insert(pii(b,t[b]));
		xs.insert(pii(d,t[d]));
		if(t[b]=='N'){
			int x;
			x=ls[b];if(x!=-1)xs.insert(pii(x,t[x]));
			x=rs[b];if(x!=-1)xs.insert(pii(x,t[x]));
		}else{
			int x;
			x=ln[b];if(x!=-1)xs.insert(pii(x,t[x]));
			x=rn[b];if(x!=-1)xs.insert(pii(x,t[x]));
		}
		if(t[d]=='N'){
			int x;
			x=ls[d];if(x!=-1)xs.insert(pii(x,t[x]));
			x=rs[d];if(x!=-1)xs.insert(pii(x,t[x]));
		}else{
			int x;
			x=ln[d];if(x!=-1)xs.insert(pii(x,t[x]));
			x=rn[d];if(x!=-1)xs.insert(pii(x,t[x]));
		}
		vector<pii> xx, yy;
		for(pii P : xs){
			xx.push_back(P);
		}
		for(pii P : ys){
			yy.push_back(P);
		}
		int sx,sy,gx,gy;
		int X = xx.size();
		int Y = yy.size();
		REP(i,Y)REP(j,X){
			if(yy[i].first==a && xx[j].first==b){
				sy=i; sx=j;
			}
			if(yy[i].first==c && xx[j].first==d){
				gy=i; gx=j;
			}
		}
		vi dist(X*Y, 1<<30);
		priority_queue<pii> Q;
		dist[sy*X+sx] = 0;
		Q.push(pii(0,sy*X+sx));
		while(!Q.empty()){
			pii P = Q.top(); Q.pop();
			if(-P.first != dist[P.second])continue;
			int y = P.second / X;
			int x = P.second % X;
			int d = dist[P.second];
			if(yy[y].second=='E' && x+1<X){
				int np = (y+0)*X+(x+1);
				int nd = d + abs(xx[x+1].first-xx[x].first);
				if(nd < dist[np]){
					dist[np] = nd;
					Q.push(pii(-nd,np));
				}
			}else if(yy[y].second == 'W' && x-1>=0){
				int np = (y+0)*X+(x-1);
				int nd = d + abs(xx[x-1].first-xx[x].first);
				if(nd < dist[np]){
					dist[np] = nd;
					Q.push(pii(-nd,np));
				}
			}
			if(xx[x].second=='S' && y+1<Y){
				int np = (y+1)*X+(x+0);
				int nd = d + abs(yy[y+1].first-yy[y].first);
				if(nd < dist[np]){
					dist[np] = nd;
					Q.push(pii(-nd,np));
				}
			}else if(xx[x].second=='N' && y-1>=0){
				int np = (y-1)*X+(x+0);
				int nd = d + abs(yy[y-1].first-yy[y].first);
				if(nd < dist[np]){
					dist[np] = nd;
					Q.push(pii(-nd,np));
				}
			}
		}
		// puts("");
		// REP(i,X)printf("(%d,%c) ",xx[i].first,(char)xx[i].second);puts("");
		// REP(i,Y)printf("(%d,%c) ",yy[i].first,(char)yy[i].second);puts("");
		// DEBUG(sx);DEBUG(sy);DEBUG(gx);DEBUG(gy);
		int ans = dist[gy*X+gx];
		if(ans==(1<<30)){
			puts("-1");
		}else{
			printf("%d\n",ans);
		}
		// break;
	}
	return 0;
}