macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
#[inline]
fn rmb(k: usize) -> usize {
    (k as isize & -(k as isize)) as usize
}
pub trait Monoid {
    type T: Clone + PartialEq;
    fn mempty(&self) -> Self::T;
    fn mappend(&self, x: &Self::T, y: &Self::T) -> Self::T;
}
#[derive(Clone, Debug)]
pub struct BinaryIndexedTree2D<M: Monoid> {
    h: usize,
    w: usize,
    bit: Vec<Vec<M::T>>,
    m: M,
}
impl<M: Monoid> BinaryIndexedTree2D<M> {
    pub fn new(h: usize, w: usize, m: M) -> BinaryIndexedTree2D<M> {
        let bit = vec![vec![m.mempty(); w + 1]; h + 1];
        BinaryIndexedTree2D {
            h: h,
            w: w,
            bit: bit,
            m: m,
        }
    }
    #[doc = " 1-indexed"]
    pub fn query(&self, i: usize, j: usize) -> M::T {
        let mut res = self.m.mempty();
        let mut a = i;
        while a > 0 {
            let mut b = j;
            while b > 0 {
                res = self.m.mappend(&res, &self.bit[a][b]);
                b -= rmb(b);
            }
            a -= rmb(a);
        }
        res
    }
    #[doc = " 1-indexed"]
    pub fn update(&mut self, i: usize, j: usize, x: M::T) {
        let mut a = i;
        while a <= self.h {
            let mut b = j;
            while b <= self.w {
                self.bit[a][b] = self.m.mappend(&self.bit[a][b], &x);
                b += rmb(b);
            }
            a += rmb(a);
        }
    }
}
pub trait Group: Monoid {
    fn invert(&self, x: &Self::T) -> Self::T;
}
impl<G: Group> BinaryIndexedTree2D<G> {
    #[doc = " 0-indexed [i1, i2) x [j1, j2)"]
    pub fn query_section(&self, i1: usize, j1: usize, i2: usize, j2: usize) -> G::T {
        let mut res = self.m.mempty();
        res = self.m.mappend(&res, &self.query(i1, j1));
        res = self.m.mappend(&res, &self.m.invert(&self.query(i1, j2)));
        res = self.m.mappend(&res, &self.m.invert(&self.query(i2, j1)));
        res = self.m.mappend(&res, &self.query(i2, j2));
        res
    }
    #[doc = " 1-indexed"]
    pub fn get_val(&self, i: usize, j: usize) -> G::T {
        self.query_section(i - 1, j - 1, i, j)
    }
    #[doc = " 1-indexed"]
    pub fn set_val(&mut self, i: usize, j: usize, x: G::T) {
        let y = self.m.invert(&self.get_val(i, j));
        let z = self.m.mappend(&y, &x);
        self.update(i, j, z);
    }
}
#[derive(Clone, Debug)]
pub struct AnyGroup<T: Clone, F: Fn(&T, &T) -> T, G: Fn(&T) -> T> {
    id: T,
    op: F,
    inv: G,
}
impl<T: Clone, F: Fn(&T, &T) -> T, G: Fn(&T) -> T> AnyGroup<T, F, G> {
    pub fn new(id: T, op: F, inv: G) -> AnyGroup<T, F, G> {
        AnyGroup {
            id: id,
            op: op,
            inv: inv,
        }
    }
}
impl<T: Clone + PartialEq, F: Fn(&T, &T) -> T, G: Fn(&T) -> T> Monoid for AnyGroup<T, F, G> {
    type T = T;
    fn mempty(&self) -> T {
        self.id.clone()
    }
    fn mappend(&self, x: &T, y: &T) -> T {
        (self.op)(x, y)
    }
}
impl<T: Clone + PartialEq, F: Fn(&T, &T) -> T, G: Fn(&T) -> T> Group for AnyGroup<T, F, G> {
    fn invert(&self, x: &T) -> T {
        (self.inv)(x)
    }
}
fn main() {
    input! { n, m, q, s: [{chars: '0'}; n], xyxy: [(usize1,usize1,usize1,usize1); q] };
    let mut bit = BinaryIndexedTree2D::new(n * 2, m * 2, AnyGroup::new(0, |&x, &y| x + y, |&x| -x));
    for i in 0..n {
        for j in 0..m {
            if s[i][j] == 1 {
                bit.update(i * 2 + 1, j * 2 + 1, 1);
            }
            if i + 1 < n && s[i][j] == 1 && s[i + 1][j] == 1 {
                bit.update((i + 1) * 2, j * 2 + 1, -1);
            }
            if j + 1 < m && s[i][j] == 1 && s[i][j + 1] == 1 {
                bit.update(i * 2 + 1, (j + 1) * 2, -1);
            }
        }
    }
    for &(x1, y1, x2, y2) in &xyxy {
        let ans = bit.query_section(x1 * 2, y1 * 2, x2 * 2 + 1, y2 * 2 + 1);
        println!("{}", ans);
    }
}


Measured memory_bytes: 145144