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<functional>
#include<algorithm>
#include<iterator>
#include<cassert>
#include<cstring>
#include<cstdio>
#include<set>
using namespace std;
//   1
// 0   2
//   3
int n,m;
struct R{int v,z,w;}e[1111];
int K[111],ce,d[111];
bool viz[111];
int ss,tt;
void ins(int a,int b,int c)
{
	//printf("ins %d %d %d\n",a,b,c);
	e[++ce]=(R){b,K[a],c};
	K[a]=ce;
}
void clg()
{
	memset(d,0x3f,sizeof(d));
	memset(K,0,sizeof(K));
	memset(viz,0,sizeof(viz));
	ce=0;
}
int q[66666];
unsigned short du,my;
void SPFA()
{
	my=1;
	q[du=0]=ss;
	d[ss]=0;
	viz[ss]=1;	
	for(;du!=my;)
	{
		int u=q[du++];
		//printf(">> %d %d %d %d\n",ss,d[ss],u,d[u]);
		viz[u]=0;
		for(int i=K[u];i;i=e[i].z)if(d[e[i].v]>d[u]+e[i].w)
		{
			d[e[i].v]=d[u]+e[i].w;
			if(!viz[e[i].v])
			{
				viz[e[i].v]=1;
				q[my++]=e[i].v;
			}
		}
	}
}
#define cmin(a,b) ((a)=(a)<(b)?(a):(b))
#define cmax(a,b) ((a)=(a)>(b)?(a):(b))
char s[111111],t[111111];
struct ds
{
	int mi[2][2][111111],ma[2][2][111111];
	ds()
	{
		memset(mi,0x3f,sizeof(mi));
		memset(ma,0xcf,sizeof(ma));
	}
	void C(int t,int x)
	{
		mi[t&1][t>>1][x]=x;
		ma[t&1][t>>1][x]=x;
	}
	void qwq()
	{
		for(int i=0;i<2;++i)	
			for(int j=0;j<2;++j)
				for(int k=(i?m:n);k;--k)
					cmin(mi[i][j][k],mi[i][j][k+1]);
		for(int i=0;i<2;++i)	
			for(int j=0;j<2;++j)
				for(int k=1;k<=(i?m:n);++k)
					cmax(ma[i][j][k],ma[i][j][k-1]);
	}
	set<int>x,y;
	void buildGraph(int a,int b,int c,int d)
	{
		int lx[22],ly[22],cx=0,cy=0;
		for(set<int>::iterator it=x.begin();it!=x.end();++it)
			if(*it>=1&&*it<=n)lx[cx++]=*it;
		for(set<int>::iterator it=y.begin();it!=y.end();++it)
			if(*it>=1&&*it<=m)ly[cy++]=*it;
		clg();
		//for(int i=0;i<cx;++i)printf("x %d %d\n",i,lx[i]);
		//for(int i=0;i<cy;++i)printf("y %d %d\n",i,ly[i]);
		//printf("%d %d %d %d\n",a,b,c,d);
		for(int i=0;i<cx;++i)
			for(int j=0;j<cy;++j)
			{
				if(j&&s[lx[i]]==0)ins(i*10+j,i*10+j-1,ly[j]-ly[j-1]);
				if(i&&t[ly[j]]==1)ins(i*10+j,i*10+j-10,lx[i]-lx[i-1]);
				if(j<cy-1&&s[lx[i]]==2)ins(i*10+j,i*10+j+1,ly[j+1]-ly[j]);
				if(i<cx-1&&t[ly[j]]==3)ins(i*10+j,i*10+j+10,lx[i+1]-lx[i]);
				if(lx[i]==a&&ly[j]==b)ss=i*10+j;
				if(lx[i]==c&&ly[j]==d)tt=i*10+j;
			}
		//printf(">> %d %d\n",ss,tt);
	}
	void werken(int a,int b,int c,int d)
	{
		x.clear();
		y.clear();
		
		x.insert(a);
		x.insert(c);
		x.insert(mi[0][0][a]);
		x.insert(mi[0][1][a]);
		x.insert(mi[0][0][c]);
		x.insert(mi[0][1][c]);
		x.insert(ma[0][0][a]);
		x.insert(ma[0][1][a]);
		x.insert(ma[0][0][c]);
		x.insert(ma[0][1][c]);
		
		y.insert(b);
		y.insert(d);
		y.insert(mi[1][0][b]);
		y.insert(mi[1][1][b]);
		y.insert(mi[1][0][d]);
		y.insert(mi[1][1][d]);
		y.insert(ma[1][0][b]);
		y.insert(ma[1][1][b]);
		y.insert(ma[1][0][d]);
		y.insert(ma[1][1][d]);
		
		buildGraph(a,b,c,d);
		SPFA();
	}
}f;
int mp[4];
int main()
{
	int q;
	scanf("%d%d%d",&n,&m,&q);
	scanf("%s",s+1);
	scanf("%s",t+1);
	for(int i=1;i<=n;++i)
	{
		if(s[i]=='W')s[i]=0;
		else s[i]=2;
		f.C(s[i],i);
	}
	for(int i=1;i<=m;++i)
	{
		if(t[i]=='N')t[i]=1;
		else t[i]=3;
		f.C(t[i],i);
	}
	f.qwq();
	for(int i=1;i<=q;++i)
	{
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		f.werken(a,b,c,d);
		printf("%d\n",::d[tt]>1e8?-1: ::d[tt]);
	}
	return 0;
}