sx,sy,ex,ey 로 테스트 케이스가 주어진다.
30분 고민했다. 모르겠다

그리고 고려할 것 → 자료형 : 2^20 x 100 = 1억 → int형으로 가능하다.
sx,sy,ex,ey → calc(ey,ex) - calc(sy,ex) - calc(ey,sx) +calc(sy,sx)
cache의 값을 bottom up 방식으로 구했다. 먼저 첫 번째 row의 것을
// (0,0) ~ (ey,ex) 로의 누적값을 구하기 
    public static void bottomUp(int ey,int ex){
        cache[0][0]=area[0][0];
        for(int c=1;c<area.length;c++){
            cache[0][c] = cache[0][c-1]+area[0][c];
        }
        int curRowSum=0;
        for(int r=1;r<area.length;r++){
            curRowSum=0;
            for(int c=0;c<area[0].length;c++){
                curRowSum+=area[r][c];
                cache[r][c] = cache[r-1][c] + curRowSum;
            }
        }
    }
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main{
    // 2^10 x 2^10 = 1048576
    public static int n,m;
    public static long cache[][]=new long[1050][1050];
    public static void Setting() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        n = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken());
        for(int x=1;x<=n;x++){
            st = new StringTokenizer(br.readLine());
            for(int y=1;y<=m;y++){
                int a = Integer.parseInt(st.nextToken());
                cache[x][y]= cache[x-1][y]+cache[x][y-1]-cache[x-1][y-1] + a;
            }
        }
/*
        System.out.println();
        for(int r=0;r<=n;r++){
            for(int c=0;c<=m;c++){
                System.out.print(cache[r][c]+" ");
            }
            System.out.println();
        }
*/
        int k = Integer.parseInt(br.readLine());
        int sx=0,sy=0,ex=0,ey=0; //
        for(int t=0;t<k;t++){
            st = new StringTokenizer(br.readLine());
            sx = Integer.parseInt(st.nextToken())-1;
            sy = Integer.parseInt(st.nextToken())-1;
            ex = Integer.parseInt(st.nextToken());
            ey = Integer.parseInt(st.nextToken());
//"("+sy+","+sx+")~("+ey+","+ex+") :"+
            System.out.println((cache[ex][ey]-cache[sx][ey]-cache[ex][sy]+cache[sx][sy]));
        }
    }
    public static void main(String[] args) throws IOException {
        Setting();
    }
}