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:
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10, D = 5;
const int inf = 1e9 + 42;

int n, m;
int dx[] = {0, -1, 0, 1};
int dy[] = {1, 0, -1, 0};
int dir_x[N], dir_y[N];
int pref_x[N][D], pref_y[N][D];
int suff_x[N][D], suff_y[N][D];
vector<int> temp;

ll solve(int sx, int sy, int tx, int ty, int di);
inline bool can_move(int x, int y, int d);
inline bool on_path(int sx, int sy, int tx, int ty, int d);
inline ll get_dist(int sx, int sy, int tx, int ty);
inline bool in_dir(int sx, int sy, int tx, int ty, int d);
inline ll get_next_after(int &sx, int &sy, int tx, int ty, int d0, int d1);

int main() {
	fast_cin();
	int q; string s, t;
	cin >> n >> m >> q >> s >> t;
	for (int x = 1; x <= n; ++x) {
		dir_x[x] = ((s[x - 1] == 'E') ? 0 : 2);
		for (int d = 0; d < 4; ++d) {
			pref_x[x][d] = pref_x[x - 1][d];
		}
		pref_x[x][dir_x[x]] = x;
	}
	suff_x[n + 1][0] = suff_x[n + 1][1] = n + 1;
	for (int x = n; x >= 1; --x) {
		for (int d = 0; d < 4; ++d) {
			suff_x[x][d] = suff_x[x + 1][d];
		}
		suff_x[x][dir_x[x]] = x;
	}
	for (int y = 1; y <= m; ++y) {
		dir_y[y] = ((t[y - 1] == 'S') ? 3 : 1);
		for (int d = 0; d < 4; ++d) {
			pref_y[y][d] = pref_y[y - 1][d];
		}
		pref_y[y][dir_y[y]] = y;
	}
	suff_y[m + 1][0] = suff_y[m + 1][1] = m + 1;
	for (int y = m; y >= 1; --y) {
		for (int d = 0; d < 4; ++d) {
			suff_y[y][d] = suff_y[y + 1][d];
		}
		suff_y[y][dir_y[y]] = y;
	}
	while (q--) {
		int sx, sy, tx, ty;
		cin >> sx >> sy >> tx >> ty;
		ll ans = inf;
		for (int d0 = 0; d0 < 4; ++d0) {
			for (int d1 = 0; d1 < 4; ++d1) {
				if (d0 % 2 == d1 % 2) {
					continue;
				}
				for (int d2 = 0; d2 < 4; ++d2) {
					if (d1 % 2 == d2 % 2) {
						continue;
					}
					for (int d3 = 0; d3 < 4; ++d3) {
						if (d2 % 2 == d3 % 2) {
							continue;
						}
						for (int d4 = 0; d4 < 4; ++d4) {
							if (d3 % 2 == d4 % 2) {
								continue;
							}
							temp = {d0, d1, d2, d3, d4};
							ans = min(ans, solve(sx, sy, tx, ty, 4));
						}
					}
				}
			}
		}
		if (ans >= inf) {
			ans = -1;
		}
		cout << ans << '\n';
	}
}

ll solve(int sx, int sy, int tx, int ty, int di) {
	if (sx == tx and sy == ty) {
		return 0;
	} else if (di < 0) {
		return inf;
	} else if (!can_move(sx, sy, temp[di])) {
		return inf;
	} else {
		int d = temp[di];
		if (on_path(sx, sy, tx, ty, d)) {
			return get_dist(sx, sy, tx, ty);
		} else if (di == 0) {
			return inf;
		}
		int x = sx, y = sy;
		ll ans = get_next_after(x, y, sx, sy, d, temp[di - 1]);
		ans += solve(x, y, tx, ty, di - 1);
		if (in_dir(sx, sy, tx, ty, d)) {
			ll cand = get_next_after(sx, sy, tx, ty, d, temp[di - 1]);
			cand += solve(sx, sy, tx, ty, di - 1);
			ans = min(ans, cand);
		}
		return ans;
	}
}

inline bool can_move(int x, int y, int d) {
	if (d == 0 or d == 2) {
		return dir_x[x] == d;
	} else {
		return dir_y[y] == d;
	}
}

inline bool on_path(int sx, int sy, int tx, int ty, int d) {
	ll dist = get_dist(sx, sy, tx, ty);
	if (sx + dx[d] * dist == tx and sy + dy[d] * dist == ty) {
		return true;
	} else {
		return false;
	}
}

inline ll get_dist(int sx, int sy, int tx, int ty) {
	return abs(sx - tx) + abs(sy - ty);
}

inline bool in_dir(int sx, int sy, int tx, int ty, int d) {
	ll d1 = get_dist(sx, sy, tx, ty);
	ll d2 = get_dist(sx + dx[d], sy + dy[d], tx, ty);
	return d2 < d1;
}

inline ll get_next_after(int &sx, int &sy, int tx, int ty, int d0, int d1) {
	int x = sx, y = sy;
	if (d0 == 0) {
		y = suff_y[ty][d1];
	} else if (d0 == 1) {
		x = pref_x[tx][d1];
	} else if (d0 == 2) {
		y = pref_y[ty][d1];
	} else {
		x = suff_x[tx][d1];
	}
	if (x < 1 or x > n or y < 1 or y > m) {
		return inf;
	} else {
		ll ans = get_dist(x, y, sx, sy);
		sx = x; sy = y;
		return ans;
	}
}