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<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef complex<ld> Point;
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

string u[2];
int sx, sy, gx, gy;
vector<int> vx[2][2];
int d[36];
struct edge {
	int to, cost;
};
vector<edge> G[36];
priority_queue<P, vector<P>, greater<P>> que;
void calc(vector<int> x, vector<int> y) {
	rep(i, 36)G[i].clear();
	fill(d, d + 36, mod);
	sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
	sort(y.begin(), y.end()); y.erase(unique(y.begin(), y.end()), y.end());
	int lx = x.size(), ly = y.size();
	int s=0, g=0;
	rep(i, x.size()) {
		if (sx == x[i]) {
			s += i * ly;
		}
		if (gx == x[i]) {
			g += i * ly;
		}
	}
	rep(i, y.size()) {
		if (sy == y[i]) {
			s += i;
		}
		if (gy == y[i]) {
			g += i;
		}
	}
	rep(i, lx - 1) {
		int dif = x[i + 1] - x[i];
		rep(j, ly) {
			int id = i * ly + j;
			if (u[1][y[j]] == 'N') {
				G[id + ly].push_back({ id,dif });
			}
			else {
				G[id].push_back({ id + ly,dif });
			}
		}
	}
	rep(i, lx) {
		rep(j, ly - 1) {
			int dif = y[j + 1] - y[j];
			int id = i * ly + j;
			if (u[0][x[i]] == 'W') {
				G[id + 1].push_back({ id,dif });
			}
			else {
				G[id].push_back({ id + 1,dif });
			}
		}
	}
	d[s] = 0; que.push({ 0,s });
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		rep(j, G[v].size()) {
			int to = G[v][j].to;
			int nd = G[v][j].cost + p.first;
			if(nd < d[to]) {
				d[to] = nd;
				que.push({ nd,to });
			}
		}
	}
	int ret = d[g];
	if (ret == mod)ret = -1;
	cout << ret << endl;
}
int trans(char t) {
	if (t == 'W' || t == 'N')return 0;
	else return 1;
}
vector<int> x[2];
void add(int id,int loc) {
	x[id].push_back(loc);
	int t = trans(u[id][loc]);
	int idd= upper_bound(vx[id][t ^ 1].begin(), vx[id][t ^ 1].end(), loc) - vx[id][t ^ 1].begin();
	if (idd < vx[id][t ^ 1].size()) {
		x[id].push_back(vx[id][t ^ 1][idd]);
	}
	if (idd >= 1) {
		x[id].push_back(vx[id][t ^ 1][idd - 1]);
	}
}
void solve() {
	int n[2], q; cin >> n[0] >> n[1] >> q;
	rep(i, 2) {
		cin >> u[i];
		rep(j, n[i]) {
			if (u[i][j] == 'W') {
				vx[0][0].push_back(j);
			}
			else if (u[i][j] == 'E') {
				vx[0][1].push_back(j);
			}
			else if (u[i][j] == 'N') {
				vx[1][0].push_back(j);
			}
			else {
				vx[1][1].push_back(j);
			}
		}
	}
	rep(i, q) {
		x[0].clear(); x[1].clear();
		cin >> sx >> sy >> gx >> gy;
		sx--; sy--; gx--; gy--;
		add(0, sx); add(1, sy);
		add(0, gx); add(1, gy);
		calc(x[0],x[1]);
		/*rep(j, x[0].size()) {
			cout << x[0][j] << endl;
		}
		cout << "in" << endl;
		rep(j, x[1].size()) {
			cout << x[1][j] << endl;
		}
		cout << "out" << endl;*/
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	//stop
	return 0;
}