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:
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i, a, n) for(LL i = (a), i##_max = (n); i < i##_max; ++i)
#define REM(i, a, n) for(LL i = (LL)(n) - 1, i##min = (a); i >= i##min; --i)
#define ALL(arr) (arr).begin(), (arr).end()
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(NULL); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
template <class T>
T Next() { T buf; cin >> buf; return buf; }

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "BinaryMatrix.h"
#include "BIT.h"
#include "Factorization.h"
#include "FlowSolver.h"
#include "Graph.h"
#include "LazySegmentTree.h"
#include "Math.h"
#include "Matrix.h"
#include "MinMax.h"
#include "Position.h"
#include "Range.h"
#include "Rational.h"
#include "SegmentTree.h"
#include "SegmentTree2D.h"
#include "SuffixArray.h"
#include "Tree.h"
#include "UnionFind.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
// template <class T>
// auto Is(const T& value) { return [value](const auto& comparand) -> bool { return comparand == value; }; }
#endif

int H, W;
vector<int> S;
vector<int> T;
int P[4][100000];
int Q[4][100000];

const int di[] = { -1, 0, 1, 0 };
const int dj[] = { 0, -1, 0, 1 };
const int BIG = 1e8;

int rec(int n, int dir, int i, int j, int gi, int gj, int h, int w) {
	if (i < 0 || i > h) return BIG;
	if (j < 0 || j > w) return BIG;
	int ri = gi - i;
	int rj = gj - j;
	if (ri <= 0 && rj == 0) return -ri;
	if (n == 0) return BIG;

	if (ri < 0) {
		if (rj < 0) {
			int lfront = h - Q[(dir + 2) % 4][h - gi];
			int lback = P[dir][gi];
			int rfront = Q[dir][i];

			int mn = BIG;
			if (lfront <= i) 
			mn = min(mn, rec(n - 1, (dir + 1) % 4, j, h - lfront, gj, h - gi, w, h) + i - lfront);
			mn = min(mn, rec(n - 1, (dir + 1) % 4, j, h - lback, gj, h - gi, w, h) + i - lback);
			mn = min(mn, rec(n - 1, (dir + 3) % 4, w - j, rfront, w - gj, gi, w, h) + i - rfront);
			return mn;
		} else {
			int rfront = h - P[(dir + 2) % 4][h - gi];
			int rback = Q[dir][gi];
			int lfront = P[dir][i];

			int mn = BIG;
			if (rfront <= i) 
			mn = min(mn, rec(n - 1, (dir + 3) % 4, w - j, rfront, w - gj, gi, w, h) + i - rfront);
			mn = min(mn, rec(n - 1, (dir + 3) % 4, w - j, rback, w - gj, gi, w, h) + i - rback);
			mn = min(mn, rec(n - 1, (dir + 1) % 4, j, h - lfront, gj, h - gi, w, h) + i - lfront);
			return mn;
		}
	} else {
		int lfront = P[dir][i];
		int rfront = Q[dir][i];

		int mn = BIG;
		mn = min(mn, rec(n - 1, (dir + 1) % 4, j, h - lfront, gj, h - gi, w, h) + i - lfront);
		mn = min(mn, rec(n - 1, (dir + 3) % 4, w - j, rfront, w - gj, gi, w, h) + i - rfront);
		return mn;
	}
}

int sub(int si, int sj, int gi, int gj) {
	int mn = BIG;
	if (T[sj] == 0) {
		mn = min(mn, rec(4, 0, si, sj, gi, gj, H, W));
	} else {
		mn = min(mn, rec(4, 2, H - si, W - sj, H - gi, W - gj, H, W));
	}

	if (S[si] == 0) {
		mn = min(mn, rec(4, 1, sj, H - si, gj, H - gi, W, H));
	} else {
		mn = min(mn, rec(4, 3, W - sj, si, W - gj, gi, W, H));
	}
	return mn;
}

void pre() {
	{
		int l = -BIG;
		int r = -BIG;
		REP(i, 0, H + 1) {
			if (!S[i]) l = i;
			if (S[i]) r = i;
			P[0][i] = l;
			Q[0][i] = r;
		}
	}

	{
		int l = -BIG;
		int r = -BIG;
		REP(j, 0, W + 1) {
			if (T[j]) l = j;
			if (!T[j]) r = j;
			P[1][j] = l;
			Q[1][j] = r;
		}
	}
	
	{
		int l = -BIG;
		int r = -BIG;
		REP(i, 0, H + 1) {
			if (S[H - i]) l = i;
			if (!S[H - i]) r = i;
			P[2][i] = l;
			Q[2][i] = r;
		}
	}

	{
		int l = -BIG;
		int r = -BIG;
		REP(j, 0, W + 1) {
			if (!T[W - j]) l = j;
			if (T[W - j]) r = j;
			P[3][j] = l;
			Q[3][j] = r;
		}
	}
}

int main() {
	int Q;
	string s, t;
	vector<PP> A;
	vector<PP> B;

	cin >> H >> W >> Q;
	--H; --W;
	cin >> s >> t;
	for (char c : s) S.push_back(c == 'E');
	for (char c : t) T.push_back(c == 'S');

	pre();

	REP(i, 0, Q) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		--a; --b; --c; --d;
		int ans = sub(a, b, c, d);
		cout << (ans >= BIG ? -1 : ans) << endl;
	}
	return 0;
}