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 nagai = long long;
#define sz(x) int((x).size())
const int N=100100;
const int Q=200200;
int n,m,q;
string s,t;
int sgn(int x){
	 return (x>0)-(x<0);
}
int dir1[N],dir2[N];

vector<int>occ1[2],occ2[2];
vector<int>inter1,inter2;
const int SZ=8;
bool used[SZ][SZ];
nagai d[SZ][SZ];
const nagai oo=0x3f3f3f3f3f3f3f3f;

struct cmp{
	bool operator()(pair<int,int>a,pair<int,int>b)const{
		if(d[a.first][a.second]!=d[b.first][b.second])
			return d[a.first][a.second]>d[b.first][b.second];
		return a<b;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>q;
	cin>>s>>t;
	for(int i=0;i<n;++i)
		dir1[i]=s[i]=='E'?1:-1;
	for(int i=0;i<m;++i)
		dir2[i]=t[i]=='S'?1:-1;
	for(int i=0;i<n;++i)
		occ1[dir1[i]>0].push_back(i);
	for(int i=0;i<m;++i)
		occ2[dir2[i]>0].push_back(i);
	for(int i=0;i<q;++i){
		 int a,b,c,D;
		 cin>>a>>b>>c>>D;
		 --a,--b,--c,--D;
		 inter1.clear();
		 inter2.clear();
		 for(int d=0;d<2;++d){
			 for(int pt:{a,c}){
				 int kek=lower_bound(occ1[d].begin(),occ1[d].end(),pt)-occ1[d].begin();
				 if(kek!=occ1[d].size())inter1.push_back(occ1[d][kek]);
				 if(kek!=0)inter1.push_back(occ1[d][kek-1]);
			 }
			 for(int pt:{b,D}){
				 int kek=lower_bound(occ2[d].begin(),occ2[d].end(),pt)-occ2[d].begin();
				 if(kek!=occ2[d].size())inter2.push_back(occ2[d][kek]);
				 if(kek!=0)inter2.push_back(occ2[d][kek-1]);
			 }
		 }
		 sort(inter1.begin(),inter1.end());
		 inter1.erase(unique(inter1.begin(),inter1.end()),inter1.end());
		 sort(inter2.begin(),inter2.end());
		 inter2.erase(unique(inter2.begin(),inter2.end()),inter2.end());
		 memset(d,0x3f,sizeof d);
		 auto find=[&](vector<int>&vec,int x){
			 return lower_bound(vec.begin(),vec.end(),x)-vec.begin();
		 };
		 int sx=find(inter1,a);
		 int sy=find(inter2,b);
		 d[sx][sy]=0;
		 memset(used,0,sizeof used);
		 int sz1=inter1.size();
		 int sz2=inter2.size();
		 int tx=find(inter1,c);
		 int ty=find(inter2,D);
		 while(true){
			 nagai mn=oo;
			 int x=-1,y=-1;
			 for(int i=0;i<sz1;++i)
				 for(int j=0;j<sz2;++j)
					 if(!used[i][j]&&d[i][j]<mn)
						 mn=d[i][j],x=i,y=j;
			 if(x==-1)break;
			 if(x==tx&&y==ty){
				 break;
			 }
			 used[x][y]=true;
			 for(int x1=0;x1<sz1;++x1)
				 if(sgn(x1-x)==dir2[inter2[y]])
					 d[x1][y]=min(d[x1][y],d[x][y]+abs(inter1[x]-inter1[x1]));
			 for(int y1=0;y1<sz2;++y1)
				 if(sgn(y1-y)==dir1[inter1[x]]){
					 d[x][y1]=min(d[x][y1],d[x][y]+abs(inter2[y1]-inter2[y]));
				 }
		 }
		 if(d[tx][ty]==oo)
			 cout<<-1<<'\n';
		 else
			 cout<<d[tx][ty]<<'\n';
	}
	return 0;
}