use contest::io::Scanner;
use std::collections::BinaryHeap;
use std::io::Write;

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

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

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

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

        let mut rows: Vec<(i32, char)> = vec![];
        let mut cols: Vec<(i32, char)> = vec![];

        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 as i32 {
                startX = i;
            }
            if rows[i].0 == c as i32 {
                goalX = i;
            }
        }
        for i in 0..cols.len() {
            if cols[i].0 == b as i32 {
                startY = i;
            }
            if cols[i].0 == d as i32 {
                goalY = i;
            }
        }
        // println!("sX sY gX gY: {} {} {} {}", startX, startY, goalX, goalY);

        let inf = 1_000_000_000 as i32;
        let mut dist = vec![vec![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();
            // println!("q.pop: {} {} {}", inf - dd, x, y);
            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));
                }
            }
        }
        // write!(std::io::stderr(), "{:?}\n", rows);
        // write!(std::io::stderr(), "{:?}\n", cols);
        // write!(std::io::stderr(), "{:?}\n", dist);
        let mut 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));
    }
}
pub mod contest {
    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);
        }
    }
}


Measured memory_bytes: 9724