#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

int **vytvorMaticu(int m, int n) {
    /* Vytvori a vrati maticu (obdlznikovu tabulku)
     * s m riadkami a n stlpcami. */
    int **a;
    a = malloc(sizeof(int *) * m);
    for (int i = 0; i < m; i++) {
        a[i] = malloc(sizeof(int) * n);
    }
    return a;
}

void zmazMaticu(int **a, int m) {
    /* Uvolni z pamate maticu s m riadkami. */
    for (int i = 0; i < m; i++) {
        free(a[i]);
    }
    free(a);
}

void nacitajMaticu(int **a, int m, int n) {
    /* Nacita hodnoty do uz vytvorenej matice
     * velkosti m krat n. */
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            scanf("%d", &a[i][j]);
        }
    }
}

int priemer(int **a, int r1, int s1, int r2, int s2) {
    /* Funkcia dostane dvojrozmernu tabulku implementovanu pomocou
     * pola smernikov, ako aj suradnice laveho horneho a praveho
     * dolneho rohu obdlznika v tejto tabulke. Vrati priemer
     * hodnot v tomto obdlzniku. */

    /* TODO VAS KOD TU */

}

int main(void) {
    /* nacitaj rozmery matice */
    int m, n;
    scanf("%d %d", &m, &n);

    /* vytvor a nacitaj maticu */
    int **a = vytvorMaticu(m, n);
    nacitajMaticu(a, m, n);

    /* nacitavaj a spracuj obdlzniky */
    while (true) {
        int r1, s1, r2, s2;
        scanf("%d %d %d %d", &r1, &s1, &r2, &s2);
        if (r1 == -1) break;
        assert(0 <= r1 && r1 <= r2 && r2 < m);
        assert(0 <= s1 && s1 <= s2 && s2 < n);

        printf("%d\n", priemer(a, r1, s1, r2, s2));
    }

    /* uvolni pamat matice */
    zmazMaticu(a, m);
}
