Given a square matrix** mat[][] **of size** N*N**, print the **sum of upper and lower triangular elements**. Upper Triangle consists of elements on the diagonal and above it. Lower triangle consists of elements on the diagonal and below it.

**Input:**

The first line consists of an integer **T** i.e number of test cases. The first line of each test case consists of an integer **N **denoting the size of the matrix. The next line contains **N*N** spaced separated integers.

**Output:**

For each testcase, in a new line, print the required output.

**Constraints:**

1 <= T <= 100

1 <= N <= 100

1 <= mat[i][j] <= 100

**Example:
Input:**

2

3

6 5 4 1 2 5 7 9 7

2

5 7 8 9

29 32

21 22

**Explanation:
Testcase1: **The given matrix is

6 5 4

1 2 5

7 9 7

The elements of upper triangle are

6 5 4

2 5

7

Sum of these elements is 6+5+4+2+5+7=29

The elements of lower triangle are

6

1 2

7 9 7

Sum of these elements is 6+1+2+7+9+7= 32

Author: saksham0751

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.

thanuvinu94 | 238 |

the_coder95 | 215 |

ShivayLamba | 208 |

sandeep.prajapati | 129 |

Ashish Kumar Vaishy | 114 |

the_coder95 | 1441 |

RishabhTanwar1 | 1110 |

thanuvinu94 | 914 |

tathagat289 | 668 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4897 |

Quandray | 4547 |

Login to report an issue on this page.