Given a matrix **C** of size **N** x **M**. You are given position of submatrix as X_{1}, Y_{1} and X_{2}, Y_{2} inside the matrix. Find the sum of all elements inside that submatrix.

**Input:**

The first line of input contains an integer T denoting the number of test cases. The first line of each test case is n and m,n is the number of rows and m is the number of columns. The second line of each test case contains C[N][M]. The third line contains four value of X_{1}, Y_{1}, X_{2}, Y_{2}. X_{1}, Y_{1} is the top left cell and X_{2}, Y_{2} is the bottom right cell.

**Output:**

Print the sum of all elements inside that submatrix.

**Constraints:**

1 ≤ T ≤ 15

1 ≤ N, M ≤ 10^{3}

1 ≤ C[N][M] ≤ 10^{6}

1 <= X_{1}, Y_{1}, X_{2}, Y_{2} <= M

**Example:**

**Input:**

2

5 6

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

3 4 4 5

3 3

9 8 7 4 2 1 6 5 3

1 2 3 3

**Output:**

78

26

**Explanation:
Testcase 2:** Sum from cell starting at position (1, 2) (1-based indexing) and ending at (3, 3) is 26.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

akhyasharma01 | 467 |

ASWATHAMA | 399 |

john_wick | 360 |

mmzeineddine | 295 |

PiyushPandey4 | 271 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

rahulnishad96 | 442 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.