#![allow(non_snake_case)]
//////////////////////////////// LIBRARY START ////////////////////////////////
#[macro_use]
pub mod contest {
    #[macro_use]
    pub mod io {
        /// Scanner
        ///
        /// # Example
        /// ```
        /// use contest::io::Scanner;
        /// let mut sc = Scanner::new("1 2 \n\n \r\t \n 3.5".as_bytes());
        /// assert_eq!("1".to_string(), sc.next::<String>());
        /// assert_eq!(2, sc.next());
        /// assert_eq!(3.5, sc.next());
        ///
        /// // To create a scanner from stdin:
        /// Scanner::new(std::io::stdin());
        /// ```
        use std;
        use std::io;
        use std::io::BufRead;

        pub struct Scanner<R: io::Read> {
            br: io::BufReader<R>,
            // Read tokens are stored in reversed order per line.
            buf: Vec<String>,
        }

        pub fn new<R: io::Read>(r: R) -> Scanner<R> {
            Scanner::new(r)
        }

        impl<R: io::Read> Scanner<R> {
            #[inline]
            pub fn new(r: R) -> Scanner<R> {
                Scanner {
                    br: io::BufReader::new(r),
                    buf: vec![],
                }
            }
            #[inline]
            pub fn next<T>(&mut self) -> T
            where
                T: std::str::FromStr,
                T::Err: std::fmt::Debug,
            {
                self.next_string()
                    .map(|s| s.parse::<T>().expect("Parse failed: "))
                    .expect("Unexpected EOF")
            }
            #[inline]
            pub fn next2<T1, T2>(&mut self) -> (T1, T2)
            where
                T1: std::str::FromStr,
                T2: std::str::FromStr,
                T1::Err: std::fmt::Debug,
                T2::Err: std::fmt::Debug,
            {
                (self.next(), self.next())
            }
            fn next_string(&mut self) -> Option<String> {
                self.buf.pop().or_else(|| match self.update() {
                    true => self.next_string(),
                    false => None,
                })
            }
            #[inline]
            fn update(&mut self) -> bool {
                let mut s = String::new();
                let res = self.br.read_line(&mut s);
                match res.expect("I/O error.") {
                    0 => false,
                    _ => {
                        self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                        true
                    }
                }
            }
        }

        #[test]
        fn test_next() {
            let mut sc = new("hoge".as_bytes());
            let s: String = sc.next();
            assert_eq!("hoge", s);
        }
    }
    #[macro_use]
    pub mod prelude {
        //! Items most contest code will use.

        use std::fmt;
        use std::iter::FromIterator;
        use std::ops::*;

        /// `Vec` indexable with `i32`, `i64` or `usize`.
        #[derive(Clone, Debug, PartialEq, PartialOrd)]
        pub struct MyVec<T>(pub Vec<T>);

        /// Creates `MyVec`
        #[macro_export]
        macro_rules! v {
    ( $( $x:expr ),* ) => {
        MyVec(vec![ $( $x, )* ])
    };
    ( $x:expr ; $n:expr ) => {
        {
            MyVec(vec![$x; $n as usize])
        }
    };
}

        impl<T: fmt::Display> fmt::Display for MyVec<T> {
            fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                let n = self.len();
                for i in 0..n {
                    let r = write!(f, "{}\n", self.0[i]);
                    if r.is_err() {
                        return r;
                    }
                }
                Ok(())
            }
        }

        impl<T> Deref for MyVec<T> {
            type Target = Vec<T>;

            fn deref(&self) -> &Vec<T> {
                &self.0
            }
        }

        impl<T> DerefMut for MyVec<T> {
            fn deref_mut(&mut self) -> &mut Vec<T> {
                &mut self.0
            }
        }

        impl<T> FromIterator<T> for MyVec<T> {
            fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
                MyVec(Vec::from_iter(iter))
            }
        }

        macro_rules! impl_index {
            ($x: ty) => {
                impl<T> Index<$x> for MyVec<T> {
                    type Output = T;

                    fn index(&self, i: $x) -> &T {
                        &self.0[i as usize]
                    }
                }

                impl<T> IndexMut<$x> for MyVec<T> {
                    fn index_mut(&mut self, i: $x) -> &mut T {
                        &mut self.0[i as usize]
                    }
                }
            };
        }

        impl_index!(i32);
        impl_index!(i64);
        impl_index!(usize);

        #[test]
        fn test_myvec() {
            let mut x = v![3, 2, 1];
            x.sort();
            assert_eq!(vec![1, 2, 3], *x);
            let i = 1i32;
            assert_eq!(2, x[i]);
            x[i] = 3;
            assert_eq!(3, x[i]);
            let u = 1usize;
            assert_eq!(3, x[u]);
            x[u] = 2;
            assert_eq!(2, x[u]);

            assert_eq!("MyVec([1, 2, 3])", format!("{:?}", x));
            assert_eq!(v![1, 2, 3], x);

            assert_eq!("1\n2\n3\n", format!("{}", x));

            let mut y = v![v![1,2]; 3];
            y[0i32][0i32] = 2i32;
            assert_eq!(vec![2, 2], *y[0i32]);
            assert_eq!(vec![1, 2], *y[1i32]);
        }
    }
}
//////////////////////////////// LIBRARY END ////////////////////////////////

use contest::io::Scanner;
use contest::prelude::MyVec;
use std::collections::BinaryHeap;

fn main() {
    let mut sc = Scanner::new(std::io::stdin());
    let n = sc.next::<i32>();
    let m = sc.next::<i32>();
    let q = sc.next::<i32>();
    let s = sc.next::<String>().chars().collect::<MyVec<char>>();
    let t = sc.next::<String>().chars().collect::<MyVec<char>>();

    let mut bottomLeft = v![-1; n];
    let mut bottomRight = v![-1; n];
    let mut upLeft = v![-1; n];
    let mut upRight = v![-1; n];
    for i in 0..n {
        if s[i] == 'W' {
            upLeft[i] = i;
            if i > 0 {
                upRight[i] = upRight[i - 1];
            }
        } else {
            upRight[i] = i;
            if i > 0 {
                upLeft[i] = upLeft[i - 1];
            }
        }
    }
    for i in (0..n).rev() {
        if s[i] == 'W' {
            bottomLeft[i] = i;
            if i + 1 < n {
                bottomRight[i] = bottomRight[i + 1];
            }
        } else {
            bottomRight[i] = i;
            if i + 1 < n {
                bottomLeft[i] = bottomLeft[i + 1];
            }
        }
    }

    let mut leftUp = v![-1; m];
    let mut leftDown = v![-1; m];
    let mut rightUp = v![-1; m];
    let mut rightDown = v![-1; m];
    for i in 0..m {
        if t[i] == 'N' {
            leftUp[i] = i;
            if i > 0 {
                leftDown[i] = leftDown[i - 1];
            }
        } else {
            leftDown[i] = i;
            if i > 0 {
                leftUp[i] = leftUp[i - 1];
            }
        }
    }
    for i in (0..m).rev() {
        if t[i] == 'N' {
            rightUp[i] = i;
            if i + 1 < m {
                rightDown[i] = rightDown[i + 1];
            }
        } else {
            rightDown[i] = i;
            if i + 1 < m {
                rightUp[i] = rightUp[i + 1];
            }
        }
    }

    for _ in 0..q {
        let a = sc.next::<i32>() - 1;
        let b = sc.next::<i32>() - 1;
        let c = sc.next::<i32>() - 1;
        let d = sc.next::<i32>() - 1;

        let mut rows = v![];
        let mut cols = v![];

        push(&mut rows, (upRight[a], 'R'));
        push(&mut rows, (upRight[a], 'R'));
        push(&mut rows, (upRight[c], 'R'));
        push(&mut rows, (bottomRight[a], 'R'));
        push(&mut rows, (bottomRight[c], 'R'));
        push(&mut rows, (upLeft[a], 'L'));
        push(&mut rows, (upLeft[c], 'L'));
        push(&mut rows, (bottomLeft[a], 'L'));
        push(&mut rows, (bottomLeft[c], 'L'));

        push(&mut cols, (leftUp[b], 'U'));
        push(&mut cols, (leftUp[d], 'U'));
        push(&mut cols, (rightUp[b], 'U'));
        push(&mut cols, (rightUp[d], 'U'));
        push(&mut cols, (leftDown[b], 'D'));
        push(&mut cols, (leftDown[d], 'D'));
        push(&mut cols, (rightDown[b], 'D'));
        push(&mut cols, (rightDown[d], 'D'));

        rows.sort();
        cols.sort();

        rows.dedup();
        cols.dedup();

        let mut startX = 10;
        let mut startY = 10;
        let mut goalX = 10;
        let mut goalY = 10;
        for i in 0..rows.len() {
            if rows[i].0 == a {
                startX = i;
            }
            if rows[i].0 == c {
                goalX = i;
            }
        }
        for i in 0..cols.len() {
            if cols[i].0 == b {
                startY = i;
            }
            if cols[i].0 == d {
                goalY = i;
            }
        }

        let inf = 1_000_000_000;
        let mut dist = v![v![inf; 8]; 8];
        let mut q = BinaryHeap::new();
        q.push((inf - 0, startX, startY));
        while !q.is_empty() {
            let (dd, x, y) = q.pop().unwrap();
            if dist[x][y] < inf {
                continue;
            }
            dist[x][y] = inf - dd;
            if rows[x].1 == 'L' {
                if y > 0 {
                    let d = cols[y].0 - cols[y - 1].0;
                    q.push((dd - d, x, y - 1));
                }
            } else {
                if y + 1 < cols.len() {
                    let d = cols[y + 1].0 - cols[y].0;
                    q.push((dd - d, x, y + 1));
                }
            }
            if cols[y].1 == 'U' {
                if x > 0 {
                    let d = rows[x].0 - rows[x - 1].0;
                    q.push((dd - d, x - 1, y));
                }
            } else {
                if x + 1 < rows.len() {
                    let d = rows[x + 1].0 - rows[x].0;
                    q.push((dd - d, x + 1, y));
                }
            }
        }
        let res = dist[goalX][goalY];
        if res == inf {
            println!("-1");
        } else {
            println!("{}", res);
        }
    }
}

fn push(rows: &mut Vec<(i32, char)>, (x, d): (i32, char)) {
    if x >= 0 {
        rows.push((x, d));
    }
}


Measured memory_bytes: 9596