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.

d_Coder00 | 134 |

dungeon_master1299 | 126 |

Astikeysingh | 120 |

rajendrashekhawat063 | 115 |

kaustavbhattachaarya | 111 |

Pulkit__Sharma__ | 646 |

Anirban166 | 531 |

abducodes | 501 |

Found_me | 454 |

Yo_Nehru | 404 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.