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,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

const int inf = 1e9;
int H,W,Q;
string sh,sw;
int ans;
V<int> Ln,Ls,Rn,Rs,Uw,Ue,Dw,De;

void dfs(int a,int b,int c,int d,bool vert,int turn,int dist){
	#define goNext(na,nb) if(a!=na || b!=nb) dfs(na,nb,c,d,!vert,turn+1,dist+abs(a-na)+abs(b-nb))
	#define goNext2(na,nb) if(a!=na || b!=nb) dfs(na,nb,c,d,vert,turn,dist+abs(a-na)+abs(b-nb))

	if(a == -1 || a == H || b == -1 || b == W) return;

	if(a == c && b == d){
		chmin(ans,dist);
		return;
	}
	if(turn == 5){
		return;
	}
	if(vert){
		if(sw[b] == 'N'){	//a--
			goNext(Uw[a],b);
			goNext(Ue[a],b);
			if(a>c){
				goNext(c,b);
				goNext2(c,b);
			}
		}else{
			goNext(Dw[a],b);
			goNext(De[a],b);
			if(a<c){
				goNext(c,b);
				goNext2(c,b);
			}
		}
	}else{
		if(sh[a] == 'W'){
			goNext(a,Ln[b]);
			goNext(a,Ls[b]);
			if(b>d){
				goNext(a,d);
				goNext2(a,d);
			}
		}else{
			goNext(a,Rn[b]);
			goNext(a,Rs[b]);
			if(b<d){
				goNext(a,d);
				goNext2(a,d);
			}
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	cin >> H >> W >> Q;
	cin >> sh >> sw;

	{
		Ln = V<int>(W,-1);
		Ls = V<int>(W,-1);
		rep(i,W){
			if(i != 0) Ln[i] = Ln[i-1], Ls[i] = Ls[i-1];
			if(sw[i] == 'N') Ln[i] = i;
			else Ls[i] = i;
		}
	}
	{
		Rn = V<int>(W,-1);
		Rs = V<int>(W,-1);
		rep(i,W){
			if(i != 0) Rn[i] = Rn[i-1], Rs[i] = Rs[i-1];
			if(sw[W-1-i] == 'N') Rn[i] = i;
			else Rs[i] = i;
		}
		reverse(all(Rn));
		reverse(all(Rs));
		rep(i,W) Rn[i] = W-1 - Rn[i], Rs[i] = W-1 - Rs[i];
	}
	{
		Uw = V<int>(H,-1);
		Ue = V<int>(H,-1);
		rep(i,H){
			if(i != 0) Uw[i] = Uw[i-1], Ue[i] = Ue[i-1];
			if(sh[i] == 'W') Uw[i] = i;
			else Ue[i] = i;
		}
	}
	{
		Dw = V<int>(H,-1);
		De = V<int>(H,-1);
		rep(i,H){
			if(i != 0) Dw[i] = Dw[i-1], De[i] = De[i-1];
			if(sh[H-1-i] == 'W') Dw[i] = i;
			else De[i] = i;
		}
		reverse(all(Dw));
		reverse(all(De));
		rep(i,H) Dw[i] = H-1-Dw[i], De[i] = H-1-De[i];
	}
	show(Ln);
	show(Ls);
	show(Rn);
	show(Rs);
	show(Ue);
	show(Uw);
	show(De);
	show(Dw);

	rep(_,Q){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		a--,b--,c--,d--;
		ans = inf;
		dfs(a,b,c,d,false,0,0);
		dfs(a,b,c,d,true,0,0);
		if(ans == inf) ans = -1;
		cout << ans << endl;
	}
}