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 ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

const ll INF = TEN(18);

int main() {
    int N, M, Q;
    string S, T;
    cin >> N >> M >> Q >> S >> T;
    debug(S, T);
    V<int> vw, ve, vn, vs;
    rep(i, N) {
        if (S[i] == 'W') {
            vw.pb(i);
        } else {
            ve.pb(i);
        }
    }
    rep(i, M) {
        if (T[i] == 'N') {
            vn.pb(i);
        } else {
            vs.pb(i);
        }
    }
    while (Q--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        --a, --b, --c, --d;
        V<int> xs{a, c}, ys{b, d};
        for (int x : {a, c}) {
            if (S[x] == 'E') {
                auto it = lower_bound(ALL(vw), x);
                if (it != vw.end()) {
                    xs.pb(*it);
                }
                if (it != vw.begin()) {
                    --it;
                    xs.pb(*it);
                }
            } else {
                auto it = lower_bound(ALL(ve), x);
                if (it != ve.end()) {
                    xs.pb(*it);
                }
                if (it != ve.begin()) {
                    --it;
                    xs.pb(*it);
                }
            }
        }
        for (int y : {b, d}) {
            if (T[y] == 'N') {
                auto it = lower_bound(ALL(vs), y);
                if (it != vs.end()) {
                    ys.pb(*it);
                }
                if (it != vs.begin()) {
                    --it;
                    ys.pb(*it);
                }
            } else {
                auto it = lower_bound(ALL(vn), y);
                if (it != vn.end()) {
                    ys.pb(*it);
                }
                if (it != vn.begin()) {
                    --it;
                    ys.pb(*it);
                }
            }
        }
        sort(ALL(xs));
        xs.erase(unique(ALL(xs)), xs.end());
        sort(ALL(ys));
        ys.erase(unique(ALL(ys)), ys.end());
        debug(xs, ys);

        a = lower_bound(ALL(xs), a) - xs.begin();
        b = lower_bound(ALL(ys), b) - ys.begin();
        c = lower_bound(ALL(xs), c) - xs.begin();
        d = lower_bound(ALL(ys), d) - ys.begin();

        using Data = pair<ll, pii>;
        priority_queue<Data, V<Data>, greater<Data>> que;
        VV<ll> ds(xs.size(), V<ll>(ys.size(), INF));
        ds[a][b] = 0;
        que.push(mp(0, mp(a, b)));
        while (!que.empty()) {
            auto t = que.top();
            que.pop();
            int x, y;
            tie(x, y) = t.se;
            if (ds[x][y] < t.fi) continue;

            if (T[ys[y]] == 'S') {
                for (int nx = x + 1; nx < xs.size(); ++nx) {
                    ll nd = ds[x][y] + abs(xs[nx] - xs[x]);
                    if (ds[nx][y] > nd) {
                        ds[nx][y] = nd;
                        que.push(mp(nd, mp(nx, y)));
                    }
                }
            } else {
                for (int nx = x - 1; nx >= 0; --nx) {
                    ll nd = ds[x][y] + abs(xs[nx] - xs[x]);
                    if (ds[nx][y] > nd) {
                        ds[nx][y] = nd;
                        que.push(mp(nd, mp(nx, y)));
                    }
                }
            }
            if (S[xs[x]] == 'E') {
                for (int ny = y + 1; ny < ys.size(); ++ny) {
                    ll nd = ds[x][y] + abs(ys[ny] - ys[y]);
                    if (ds[x][ny] > nd) {
                        ds[x][ny] = nd;
                        que.push(mp(nd, mp(x, ny)));
                    }
                }
            } else {
                for (int ny = y - 1; ny >= 0; --ny) {
                    ll nd = ds[x][y] + abs(ys[ny] - ys[y]);
                    if (ds[x][ny] > nd) {
                        ds[x][ny] = nd;
                        que.push(mp(nd, mp(x, ny)));
                    }
                }
            }
        }
        ll ans = ds[c][d];
        if (ans == INF) ans = -1;
        cout << ans << "\n";
    }
    return 0;
}