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>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005,dir[2]={-1,1},inf=1e8;
struct node{int x,y,d;}; vector<node> R1,C1,R2,C2;
int x[N][2],y[N][2],r[N],c[N];
int n,m,Q,a,b,u,v;
char sr[N],sc[N];

void dfs1R(int k,int a,int b,int d);
void dfs1C(int k,int a,int b,int d);
void dfs2R(int k,int a,int b,int d);
void dfs2C(int k,int a,int b,int d);

void dfs1R(int k,int a,int b,int d){
	if(a<1||a>n||b<1||b>m) return;
	R1.pb((node){a,b,d});
	if(!k) return;
	dfs1C(k-1,a,b,d);
	dfs1C(k-1,a,y[b][r[a]],d+abs(y[b][r[a]]-b));
}
void dfs1C(int k,int a,int b,int d){
	if(a<1||a>n||b<1||b>m) return;
	C1.pb((node){a,b,d});
	if(!k) return;
	dfs1R(k-1,a,b,d);
	dfs1R(k-1,x[a][c[b]],b,d+abs(x[a][c[b]]-a));
}
void dfs2R(int k,int a,int b,int d){
	if(a<1||a>n||b<1||b>m) return;
	R2.pb((node){a,b,d});
	if(!k) return;
	dfs2C(k-1,a,b,d);
	dfs2C(k-1,a,y[b][1-r[a]],d+abs(y[b][1-r[a]]-b));
}
void dfs2C(int k,int a,int b,int d){
	if(a<1||a>n||b<1||b>m) return;
	C2.pb((node){a,b,d});
	if(!k) return;
	dfs2R(k-1,a,b,d);
	dfs2R(k-1,x[a][1-c[b]],b,d+abs(x[a][1-c[b]]-a));
}

int main(){
	read(n),read(m),read(Q);
	scanf("%s%s",sr+1,sc+1);
	r[0]=r[n+1]=c[0]=c[m+1]=-1;
	rep(i,1,n) r[i]=(sr[i]=='E');
	rep(i,1,m) c[i]=(sc[i]=='S');
	rep(i,1,n) x[i][0]=(r[i]!=r[i-1]?i-1:x[i-1][0]);
	per(i,n,1) x[i][1]=(r[i]!=r[i+1]?i+1:x[i+1][1]);
	rep(i,1,m) y[i][0]=(c[i]!=c[i-1]?i-1:y[i-1][0]);
	per(i,m,1) y[i][1]=(c[i]!=c[i+1]?i+1:y[i+1][1]);
	while(Q--){
		read(a),read(b),read(u),read(v);
		R1.clear(),C1.clear(),R2.clear(),C2.clear();
		dfs1R(2,a,b,0),dfs1C(2,a,b,0);
		dfs2R(2,u,v,0),dfs2C(2,u,v,0);
		int ans=inf;
		for(auto p:R1) for(auto q:C2){
			int R=(q.y-p.y)*dir[r[p.x]];
			int C=(q.x-p.x)*dir[c[q.y]];
			if(R>=0&&C>=0) ans=min(ans,R+C+p.d+q.d);
		}
		for(auto p:C1) for(auto q:R2){
			int R=(q.y-p.y)*dir[r[q.x]];
			int C=(q.x-p.x)*dir[c[p.y]];
			if(R>=0&&C>=0) ans=min(ans,R+C+p.d+q.d);
		}
		printf("%d\n",ans>=inf?-1:ans);
	}
	return 0;
}