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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
bool Hs[100000];
bool Ws[100000];
int HPT[100001];
int HMT[100001];
int HPF[100001];
int HMF[100001];
int WPT[100001];
int WMT[100001];
int WPF[100001];
int WMF[100001];
pair<int,int> X[6];
void Calc(){
	int H = rei();
	int W = rei();
	int Q = rei();
	string S = res();
	string T = res();
	for(int i=0;i<H;i++){
		Hs[i] = S[i] == 'E';
	}
	for(int i=0;i<W;i++){
		Ws[i] = T[i] == 'S';
	}	
	for(int i=0;i<H;i++){
		if(Hs[i]){
			HMT[i+1] = i+1;
			HMF[i+1] = HMF[i];
		}
		else{
			HMF[i+1] = i+1;
			HMT[i+1] = HMT[i];
		}
	}
	HPF[H] = H;
	HPT[H] = H;
	for(int i=H-1;i>=0;i--){
		if(Hs[i]){
			HPT[i] = i;
			HPF[i] = HPF[i+1];
		}
		else{
			HPF[i] = i;
			HPT[i] = HPT[i+1];
		}
	}
	for(int i=0;i<W;i++){
		if(Ws[i]){
			WMT[i+1] = i+1;
			WMF[i+1] = WMF[i];
		}
		else{
			WMF[i+1] = i+1;
			WMT[i+1] = WMT[i];
		}
	}
	WPF[W] = W;
	WPT[W] = W;
	for(int i=W-1;i>=0;i--){
		if(Ws[i]){
			WPT[i] = i;
			WPF[i] = WPF[i+1];
		}
		else{
			WPF[i] = i;
			WPT[i] = WPT[i+1];
		}
	}
	for(int query=0;query<Q;query++){
		int start = 0;
		stack<tuple<int,int,bool,int,int>> sp;
		int hb = rei()-1;
		int wb = rei()-1;
		int ha = rei()-1;
		int wa = rei()-1;
		sp.push(make_tuple(hb,wb,true,0,0));
		sp.push(make_tuple(hb,wb,false,0,0));
		int nextx,nexty;
		int ans = 1000000000;
		while(!sp.empty()){
			tuple<int,int,bool,int,int> t = sp.top();
			sp.pop();
			int x = get<0>(t);
			int y = get<1>(t);
			int coun = get<3>(t);
			int cost = get<4>(t);
			int d = 0;
			if(get<2>(t)){
				if(Ws[y]){
					if(ha > x){
						if(HPF[ha] != H){
							nextx = HPF[ha];
							nexty = y;
							X[d++] = {nextx,nexty};
						}
						if(HPT[ha] != H){
							nextx = HPT[ha];
							nexty = y;
							X[d++] = {nextx,nexty};
						}
					}
					if(HPF[x] != x && HPF[x] != H){
						nextx = HPF[x];
						nexty = y;
						X[d++] = {nextx,nexty};
					}
					if(HPT[x] != x && HPT[x] != H){
						nextx = HPT[x];
						nexty = y;
						X[d++] = {nextx,nexty};
					}
				}
				else{
					if(ha < x){
						if(HMF[ha+1] != 0){
							nextx = HMF[ha+1]-1;
							nexty = y;
							X[d++] = {nextx,nexty};
						}
						if(HMT[ha+1] != 0){
							nextx = HMT[ha+1]-1;
							nexty = y;
							X[d++] = {nextx,nexty};
						}
					}
					if(HMF[x+1] != x+1 && HMF[x+1] != 0){
						nextx = HMF[x+1]-1;
						nexty = y;
						X[d++] = {nextx,nexty};
					}
					if(HMT[x+1] != x+1 && HMT[x+1] != 0){
						nextx = HMT[x+1]-1;
						nexty = y;
						X[d++] = {nextx,nexty};
					}
				}
			}
			else{
				if(Hs[x]){
					if(wa > y){
						if(WPF[wa] != W){
							nexty = WPF[wa];
							nextx = x;
							X[d++] = {nextx,nexty};
						}
						if(WPT[wa] != W){
							nexty = WPT[wa];
							nextx = x;
							X[d++] = {nextx,nexty};
						}
					}
					if(WPF[y] != y && WPF[y] != W){
						nexty = WPF[y];
						nextx = x;
						X[d++] = {nextx,nexty};
					}
					if(WPT[y] != y && WPT[y] != W){
						nexty = WPT[y];
						nextx = x;
						X[d++] = {nextx,nexty};
					}
				}
				else{
					if(wa < y){
						if(WMF[wa+1] != 0){
							nexty = WMF[wa+1]-1;
							nextx = x;
							X[d++] = {nextx,nexty};
						}
						if(WMT[wa+1] != 0){
							nexty = WMT[wa+1]-1;
							nextx = x;
							X[d++] = {nextx,nexty};
						}
					}
					if(WMF[y+1] != y+1 && WMF[y+1] != 0){
						nexty = WMF[y+1]-1;
						nextx = x;
						X[d++] = {nextx,nexty};
					}
					if(WMT[y+1] != y+1 && WMT[y+1] != 0){
						nexty = WMT[y+1]-1;
						nextx = x;
						X[d++] = {nextx,nexty};
					}
				}
			}
			if(coun == 4){
				for(int i=0;i<d;i++){
					if(X[i].first == ha && X[i].second == wa){
						ans = min(ans,abs(X[i].first-x)+abs(X[i].second-y)+cost);
					}
				}
			}
			else{
				for(int i=0;i<d;i++){
					if(X[i].first == ha && X[i].second == wa){
						ans = min(ans,abs(X[i].first-x)+abs(X[i].second-y)+cost);
					}
					else{
						sp.push(make_tuple(X[i].first,X[i].second,!get<2>(t),coun+1,abs(X[i].first-x)+abs(X[i].second-y)+cost));
					}
				}
			}
		}
		if(ans == 1000000000){
			cout << "-1\n"; 
		}
		else{
			cout << ans << "\n"; 
		}
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}